-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
pre-commit-ast-grep | ||
[](https://github.com/boidolr/pre-commit-ast-grep/tags) | ||
[](https://github.com/pre-commit/pre-commit) | ||
[](https://github.com/boidolr/pre-commit-ast-grep/actions/workflows/test.yaml) | ||
[](https://github.com/pre-commit/pre-commit) | ||
================ | ||
|
||
|
||
Minimal git hooks to run [`ast-grep`](https://github.com/ast-grep/ast-grep) based on the [pre-commit](https://github.com/pre-commit/pre-commit) framework. | ||
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 pre-commit-ast-grep with pre-commit | ||
|
||
Add this to your `.pre-commit-config.yaml`: | ||
``` | ||
- repo: https://github.com/boidolr/pre-commit-ast-grep | ||
rev: v0.2.0 # Use the ref you want to point at | ||
rev: v0.18.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/pre-commit-ast-grep | ||
rev: v0.2.0 # Use the ref you want to point at | ||
rev: v0.18.1 # Use the ref you want to point at | ||
hooks: | ||
- id: ast-grep | ||
args: ["--update-all"] | ||
args: ["--update-all"] | ||
``` | ||
|
||
When executing rewrites, the commit hook will fail for any severity. | ||
|
||
Mixing rules with fixes and without fixes with the "--update-all" option is currently not supported. | ||
|
||
|
||
### Provide explicit configuration | ||
|
||
``` | ||
- repo: https://github.com/boidolr/pre-commit-ast-grep | ||
rev: v0.2.0 # Use the ref you want to point at | ||
rev: v0.18.1 # Use the ref you want to point at | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ | |
"extends": [ | ||
"github>boidolr/actions", | ||
"github>boidolr/actions//presets/precommit" | ||
], | ||
"ignoreTests": true | ||
] | ||
} |