Structural Search and Rewrite code at large scale using precise AST pattern.
Actively maintained. Last release 2 weeks ago, commits in 25 of the last 26 weeks. A safe choice.
pip install ast-grep-cli
ast-grep(sg)
ast-grep(sg) is a CLI tool for code structural search, lint, and rewriting.
Introduction
ast-grep is an abstract syntax tree based tool to search code by pattern code. Think of it as your old-friend grep, but matching AST nodes instead of text.
You can write patterns as if you are writing ordinary code. It will match all code that has the same syntactical structure.
You can use $ sign + upper case letters as a wildcard, e.g. $MATCH, to match any single AST node. Think of it as regular expression dot ., except it is not textual.
Try the online playground for a taste!
