.ci/ast-grep/README.md
ast-grep is a tool for querying source code in a (relatively)
language-agnostic manner. It allows us to write lint rules that target patterns
that are specific to our codebase and therefore not covered by tools like
luacheck.
See the installation docs for guidance.
The workflow for writing a new lint rule looks like this:
.ci/ast-grep/rules/${name}.yml
ast-grep scan --filter ${name} [paths...] to evaluate your rule's behavior.ci/ast-grep/tests/${name}-test.yml
valid and invalid code snippetsast-grep test --interactive* to test the rulegit add .gi/ast-grep && git commit ...* ast-grep test uses a file snapshot testing pattern. Almost any time a rule
or test is created/modified, the snapshots must be updated. The --interactive
flag for ast-grep test will prompt you to accept these updates. The snapshots
provide very granular testing for rule behavior, but for many cases where we
just care about whether or not a rule matches a certain snippet of code, they
can be overkill. Use ast-grep --update-all to automatically accept and save
new snapshots.
ast-grep is executed in the (ast-grep lint
workflow). In addition to running the linter,
this workflow also performs self-tests and ensures that all existing rules are
well-formed and have tests associated with them.