ast-grep AST Search & Rewrite

0•

Searches, lints, and refactors codebases using syntax-aware Abstract Syntax Tree (AST) patterns and YAML rules with ast-grep.

Provides expert guidance on using ast-grep (sg) for syntax-aware code searches, structural refactoring, and custom rule-based linting. This skill assists developers in crafting precise AST pattern queries with metavariables, building robust YAML lint rules using atomic and relational operators, executing interactive code rewrites, and maintaining regression test suites via sgconfig.yml. It is ideal when regex-based search tools fall short in understanding code syntax across languages such as TypeScript, Python, Rust, Go, and Java.

Key Features

01Configure project-wide linting pipelines and scanning configurations with sgconfig.yml
02Construct syntax-aware AST search patterns using single-node, sequence, and wildcard metavariables
03Execute structural code rewrites and API migrations interactively or across entire codebases
04Design and run automated test suites with sg test to validate pattern matching and fixes
05Author custom YAML lint rules combining atomic, relational, and composite match operators
060 GitHub stars

Use Cases

01Migrating deprecated APIs and updating code idioms across multi-file repositories
02Creating custom security and architectural lint rules tailored to internal team standards
03Locating complex, nested code structures where regex and textual grep tools produce false positives