https://github.com/boidolr/ast-grep-pre-commit
Structural lint and rewriting with ast-grep for pre-commit hooks
https://github.com/boidolr/ast-grep-pre-commit
ast-grep codemod git-hooks pre-commit refactoring
Last synced: about 1 year ago
JSON representation
Structural lint and rewriting with ast-grep for pre-commit hooks
- Host: GitHub
- URL: https://github.com/boidolr/ast-grep-pre-commit
- Owner: boidolr
- License: mit
- Created: 2024-02-01T17:39:03.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-02T06:52:26.000Z (about 1 year ago)
- Last Synced: 2025-06-02T17:24:40.083Z (about 1 year ago)
- Topics: ast-grep, codemod, git-hooks, pre-commit, refactoring
- Homepage:
- Size: 56.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
ast-grep-pre-commit
[](https://github.com/boidolr/ast-grep-pre-commit/tags)
[](https://github.com/boidolr/ast-grep-pre-commit/actions/workflows/test.yaml)
[](https://github.com/pre-commit/pre-commit)
================
Minimal git hook to run [ast-grep](https://github.com/ast-grep/ast-grep) based on the [pre-commit](https://github.com/pre-commit/pre-commit) framework.
## Using ast-grep-pre-commit with pre-commit
Add this to your `.pre-commit-config.yaml`:
```
- repo: https://github.com/boidolr/ast-grep-pre-commit
rev: 0.31.1 # 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.
### Automatically execute rewrites
```
- repo: https://github.com/boidolr/ast-grep-pre-commit
rev: 0.31.1
hooks:
- id: ast-grep
args: ["--update-all"]
```
### Provide explicit configuration
```
- repo: https://github.com/boidolr/ast-grep-pre-commit
rev: 0.31.1
hooks:
- id: ast-grep
args: ["--config", "/some/path/sgconfig.yaml"]
```
## How to write rules
See https://ast-grep.github.io/ for details on `ast-grep` and how to write linters and rewriters.