← ClaudeAtlas

ast-greplisted

Effective code search, analysis, and refactoring using ast-grep (sg). Use this skill for precise AST-based code modifications, structural search, and linting.
OutlineDriven/odin-claude-plugin · ★ 27 · Code & Development · score 80
Install: claude install-skill OutlineDriven/odin-claude-plugin
# ast-grep (sg) ast-grep is a fast and polyglot tool for code searching, linting, and rewriting based on Abstract Syntax Trees (AST). It excels at structural search and replace where regex fails. ## When to use - **Structural Search**: Finding code based on structure (e.g., "all function calls to `foo` with 2 arguments") regardless of whitespace. - **Refactoring**: Renaming variables, changing function signatures, or transforming code patterns safely. - **Linting**: Creating custom rules to enforce code style or best practices. - **Code Analysis**: Extracting information from codebases. ## Quick Start ### CLI Basics ```bash # Search (pattern must be in single quotes) ast-grep -p '$A + $B' --lang ts # Rewrite (dry run) ast-grep -p '$A != null' --rewrite '$A' --lang ts # Interactive Rewrite ast-grep -p 'var $A = $B' --rewrite 'const $A = $B' --interactive ``` ### Pattern Syntax - **Meta-variables**: `$VAR` matches any single node. - **Multi-meta-variables**: `$$$ARGS` matches zero or more nodes (list of items). - **Wildcard**: `$_` matches any node (non-capturing). - **Anonymous**: `$$` matches any list of nodes (non-capturing). See [Pattern Syntax](references/pattern-syntax.md) for details. ## Core Concepts Understanding **Named vs Unnamed nodes** and **Matching Strictness** is crucial for precise patterns. - **Named Nodes**: `identifier`, `function_definition` (matched by `$VAR`). - **Unnamed Nodes**: `(`, `)`, `;` (skipped by default in `smart` mode). - **Strict