AST-Grep Structural Search
Performs structural code searching and refactoring to resolve ambiguous text matching and formatting variations.
ast-grep provides a powerful alternative to traditional text-based search and edit tools by leveraging Abstract Syntax Trees (AST) for code manipulation. It allows for precise refactoring of complex code structures—such as function signatures and class definitions—regardless of whitespace, line breaks, or naming variations. By using structural patterns instead of exact string matches, it effectively eliminates the common 'old_string not unique' error, making it an essential tool for large-scale codebase migrations and systematic structural changes.
Key Features
01Advanced refactoring for function signatures, method calls, and class structures
023 GitHub stars
03Structural pattern matching using metavariables like $VAR and $$$ARGS
04Strategic integration with standard edit tools to resolve text ambiguity
05Formatting-independent code search that ignores whitespace and line breaks
06Language-specific optimization for JavaScript, TypeScript, Python, Go, and Rust
Use Cases
01Refactoring function signatures or method names across a large codebase where text search is ambiguous
02Standardizing code patterns across different formatting styles or indentation levels
03Performing complex structural replacements in nested code logic where simple regex fails