Skip to content

Instantly share code, notes, and snippets.

@elithrar
Last active January 16, 2026 17:49
Show Gist options
  • Select an option

  • Save elithrar/de9c928e04bef1a15752958528e68260 to your computer and use it in GitHub Desktop.

Select an option

Save elithrar/de9c928e04bef1a15752958528e68260 to your computer and use it in GitHub Desktop.
2026/01/16 - lint (and rewrite) Cloudflare Workers code using ast-grep (https://ast-grep.github.io/)

Code that uses await here for a synchronous call:

export class MyDurableObject extends DurableObject {
  async query() {
    const rows = await this.ctx.storage.sql.exec("select 1");
    return rows;
  }
}

ast-grep invocation (dry-run/lint):

ast-grep scan --rule .rules/synchronous-storage-sql-codemod.yaml ./path/to/codebase
# Outputs:
/src/await-example.ts:7:18: warning[no-await-storage-sql]: Remove await; storage.sql.* is synchronous.

ast-grep invocation (rewrite/update):

ast-grep scan --rule .rules/synchronous-storage-sql-codemod.yaml -U ./path/to/codebase

after:

export class MyDurableObject extends DurableObject {
  async query() {
    const rows = this.ctx.storage.sql.exec("select 1");
    return rows;
  }
}
# Assuming your rules are in .rules/* within your repo:
# ast-grep scan --rule .rules/synchronous-storag-sql-codemod.yaml -U
id: no-await-storage-sql
language: ts
rule:
pattern: await $CALL
constraints:
CALL:
pattern: this.ctx.storage.sql.$METHOD($$$ARGS)
fix: $CALL
message: Remove await; storage.sql.* is synchronous.
severity: warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment