grep | structural search/rewrite tool for many languages

1 min read Original article ↗

AST-GREPFind Code by Syntax

ast-grep(sg) is a fast and polyglot tool for code structural search, lint, rewriting at large scale.

ast-grep



  • Scan as Linter

    ast-grep is a versatile and flexible tool for linting code with AST patterns. You can easily add new customized rules with intuitive syntax and enjoy pretty error reporting out of box.

    ast-grep scan


  • Programmatic Usage

    ast-grep also provides node-js binding to access syntax trees programmatically. You can use jQuery like utility methods to traverse syntax tree nodes. Node API also has opt-in type safety.

    npm install @ast-grep/napi


⚡️

Performant

Blazing fast search and replace across thousands of source code files, powered by parallel Rust.

📚

Polyglot

Supports many programming languages out of box! You can also register your own tree-sitter parsers by dynamic loading.

👟

Progressive

Supports multiple forms of usages from one-line command to fully programmatic interface, scaling to different scenarios.

🛠️

Pragmatic

Not a toy but a batteries-included tool with interactive codemod, language server and testing tool.

20+ Supported Languages