Minimal git hook to run ast-grep based on the pre-commit framework.
Add this to your .pre-commit-config.yaml
:
- repo: https://github.com/boidolr/ast-grep-pre-commit
rev: 0.34.4 # Use the ref you want to point at
hooks:
- id: ast-grep
Note that only rules with a severity of "error" will lead to the commit hook failing.
- repo: https://github.com/boidolr/ast-grep-pre-commit
rev: 0.34.4
hooks:
- id: ast-grep
args: ["--update-all"]
- repo: https://github.com/boidolr/ast-grep-pre-commit
rev: 0.34.4
hooks:
- id: ast-grep
args: ["--config", "/some/path/sgconfig.yaml"]
The hook version mirror the version of ast-grep. If for any reason you want up- or downgrade the ast-grep version used by the hook, for example to get an update before the hook was published, you can do so:
- repo: https://github.com/boidolr/ast-grep-pre-commit
rev: 0.34.4
hooks:
- id: ast-grep
additional_dependencies: ["@ast-grep/[email protected]"] # set the desired version
See https://ast-grep.github.io/ for details on ast-grep
and how to write linters and rewriters.