ast-grep (sg) is a CLI tool for code structural search, lint, and rewriting.
ast-grep is an abstract syntax tree based tool to search code by pattern code. Think of it as your old-friend grep, but matching AST nodes instead of text. You can write patterns as if you are writing ordinary code. It will match all code that has the same syntactical structure. You can use $ sign + upper case letters as a wildcard, e.g. $MATCH, to match any single AST node. Think of it as regular expression dot ., except it is not textual.
ast-grep’s core is an algorithm to search and replace code based on abstract syntax tree produced by tree-sitter. It can help you to do lightweight static analysis and massive scale code manipulation in an intuitive way.
This is free and open source software.
Features include:
- Intuitive pattern to find and replace AST. ast-grep’s pattern looks like ordinary code you would write every day (you could say the pattern is isomorphic to code).
- jQuery like API for AST traversal and manipulation.
- YAML configuration to write new linting rules or code modification.
- Written in compiled language, with tree-sitter based parsing and utilizing multiple cores.
Website: github.com/ast-grep/ast-grep
Support:
Developer: Herrington Darkholme
License: MIT License

ast-grep is written in Rust. Learn Rust with our recommended free books and free tutorials.
Related Software
| General Purpose Linter Tools | |
|---|---|
| Super-linter | Collection of linters and code analyzers |
| Prettier | Opinionated code formatter |
| semgrep | Static analysis for many languages |
| ast-grep | Performs structural search, lint and rewriting |
| MegaLinter | Analyzes the consistency of your code |
| commitlint | Lint commit messages |
| tidyall | All-in-one code tidier and validator |
| Violations Lib | Parse report files from static code analysis |
Read our verdict in the software roundup.
LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more. Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion. Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README. |


Please read our Comment Policy before commenting.