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.

    ast-grep -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.

    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

20+ Supported Languages

See more in the full list. Custom languages are also loadable.

Who is using ast-grep

Made with ❤️ with Rust