Write and debug ast-grep rules for structural code search and rewrite. Use when tasks require AST-aware matching (not plain text), such as finding specific syntax shapes, relational patterns (inside/has), composite logic (all/any/not), or precise code refactors across a codebase.
Translate user intent into sg patterns/rules, validate quickly, then run against target scope.
Pin down:
Use sg run --pattern first.
sg run --pattern 'console.log($ARG)' --lang javascript src
For relational/composite logic (inside / has / precedes / follows / all / any / not / matches), use sg scan --rule.
# rule.yml