← ClaudeAtlas

ast-greplisted

Search and rewrite Python structurally with ast-grep patterns, meta-variables, YAML rules, and JSON output. Use for AST-aware code search, lint rules, or safe bulk refactors.
fmind/dot · ★ 4 · Data & Documents · score 80
Install: claude install-skill fmind/dot
# ast-grep Structural code search and rewrite: a pattern is real code with meta-variables, matched against the syntax tree, so it ignores formatting and never matches inside strings or comments. Use it where `rg` gives false positives and where a refactor must touch every call site exactly once; plain text search stays with `rg`. ## Commands ```bash ast-grep run -p 'print($$$ARGS)' -l python # search; run is the default subcommand ast-grep run -p 'print($$$ARGS)' -r 'logger.info($$$ARGS)' -l python # dry run: prints the diff, changes nothing ast-grep run -p 'print($$$ARGS)' -r 'logger.info($$$ARGS)' -l python --update-all # apply after reviewing the dry run (-i to confirm per hunk) ast-grep run -p 'os.getenv($KEY)' -l python --json=compact # structured output; --json=stream gives one object per line ast-grep scan # every rule in sgconfig.yml ast-grep scan -r rules/no-print.yml --format github # one rule file; GitHub annotations in CI ``` ## Workflow 1. **Write the pattern as code**: `$NAME` matches one node, `$$$NAME` a sequence (arguments, statements), `$_` a node without binding; always pass `-l <lang>` so the pattern parses in the right grammar, and use `--debug-query=ast` when a pattern that should match does not. 1. **Search first**: run without `-r`, read the matches with `-C 2` for context, and tune