Skip to content

ast-grep integration for pre-commit hooks

License

Notifications You must be signed in to change notification settings

boidolr/ast-grep-pre-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ast-grep-pre-commit tag Build pre-commit

Minimal git hook to run ast-grep based on the 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.22.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.

Automatically execute rewrites

  - repo: https://github.com/boidolr/ast-grep-pre-commit
    rev: 0.22.4
    hooks:
      - id: ast-grep
        args: ["--update-all"]

Provide explicit configuration

  - repo: https://github.com/boidolr/ast-grep-pre-commit
    rev: 0.22.4
    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.