ast-grepのrule
yamlで書かれた、ast-grep用のクエリ
rule毎に、idなり対象言語(language)を書く
ruleは、ast-grepのPatternの組み合わせで書くみたい
ワンライナーのPatternより複雑なクエリが書ける
docs
ast-grep: Rule Object
ast-grep: Utility Rule
例
awaitなしでPromise.allが呼ばれている箇所をgrepするためのrule
code:yaml
id: no-await-in-promise-all
language: TypeScript
rule:
pattern: Promise.all($A)
has:
pattern: await $_
stopBy: end
rule:の内部の書き方は、用意されているクエリを学ぶ必要がある
docsではこれを、(Atomic Ruleなどを包含し)ast-grep: Rule Objectと呼んでいる
ルールを実行する
λ ast-grep scanを使う
一度に 1 つのルールを実行する
$ ast-grep scan --rule no-await-in-promise-all.yml test.ts