ast-grep

Solid

Run code analysis and refactoring with ast-grep. Use when doing AST-based modifications, structural search, linting across code shape, or replacing regex-fragile transformations.

AI & Automation 33 stars 0 forks Updated today Apache-2.0

Install

View on GitHub

Quality Score: 83/100

Stars 20%
51
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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. ## The helper: validate first, dry-run first `scripts/ast_grep_helper.py` wraps two safety gates: ```bash # Lint a pattern before you search with it (exit 0 valid / exit 2 malformed; flags regex-smell) python3 scripts/ast_grep_helper.py validate '$A + $B' --lang ts # Preview a...

Details

Author
OutlineDriven
Repository
OutlineDriven/odin-claude-plugin
Created
8 months ago
Last Updated
today
Language
Python
License
Apache-2.0

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category