Skip to content

AST-GREP

Find Code by Syntax

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

ast-grep

  • Search and Rewrite

    ast-grep is a code tool for structural search and replace. It is like syntax-aware grep/sed! You can write code patterns to locate and modify code, based on AST, in thousands of files, interactively.

    sg -p '$A && $A()' -r '$A?.()'

  • 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.

    sg scan

  • Programmatic Usage

    ast-grep also provides node-js binding for manipulating syntax trees programmatically. You can use jQuery like utility methods to traverse and manipulate syntax tree nodes, or use operators to compose complex matching from simple patterns.

    npm install @ast-grep/napi

Supported Languages

Who is using ast-grep

Made with ❤️ with Rust