skills/ship-faster/skills/tool-ast-grep-rules/SKILL.md
Write AST-based code search and rewrite rules using ast-grep YAML. Create linting rules, code modernizations, and API migrations with auto-fix. Use when the user mentions ast-grep, tree-sitter patterns, code search rules, lint rules with YAML, AST matching, or code refactoring patterns.
npx skillsauth add enuno/claude-command-and-control tool-ast-grep-rulesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
ast-grep uses tree-sitter to parse code into AST, enabling precise pattern matching. Rules are defined in YAML for linting, searching, and rewriting code.
id: no-console-log
language: JavaScript
rule:
pattern: console.log($$$ARGS)
fix: logger.log($$$ARGS)
message: Replace console.log with logger
Project-level scanning requires an sgconfig.yml configuration file:
# sgconfig.yml (project root)
ruleDirs:
- rules # Rule directory, recursively loads all .yml files
Typical project structure:
my-project/
├── sgconfig.yml
├── rules/
│ ├── no-console.yml
│ └── custom/
│ └── team-rules.yml
└── src/
Running project scan:
ast-grep scan # Automatically finds sgconfig.yml
ast-grep scan --config path/to/sgconfig.yml # Specify config
Note:
ast-grep scancommand requiressgconfig.yml, whileast-grep run -pcan be used standalone.
Check only without fixing, used for CI/editor hints:
# rules/no-console-log.yml
id: no-console-log
language: JavaScript
severity: warning
message: Avoid console.log in production code
rule:
pattern: console.log($$$ARGS)
Verify:
ast-grep scan -r rules/no-console-log.yml src/
Add fix when auto-fix is needed:
id: no-console-log
language: JavaScript
severity: warning
message: Replace console.log with logger
rule:
pattern: console.log($$$ARGS)
fix: logger.log($$$ARGS)
Apply fix:
ast-grep scan -r rules/no-console-log.yml --update-all src/
- [ ] 1. Explore pattern with CLI: ast-grep -p 'pattern' src/
- [ ] 2. Create rule file (.yml)
- [ ] 3. Verify: ast-grep scan -r rule.yml src/
- [ ] 4. If false positives → add constraints → re-verify
Debug AST structure:
ast-grep -p 'console.log($ARG)' --debug-query ast
| Element | Syntax | Example |
|---------|--------|---------|
| Single node | $VAR | console.log($MSG) |
| Multiple nodes | $$$ARGS | fn($$$ARGS) |
| Same content | Use same name | $A == $A |
| Non-capturing | $_VAR | $_FN($_FN) |
| Type | Purpose | Example |
|------|---------|---------|
| pattern | Match code structure | pattern: if ($COND) {} |
| kind | Match AST node type | kind: function_declaration |
| all | Match ALL conditions | all: [pattern: X, kind: Y] |
| any | Match ANY condition | any: [pattern: var $A, pattern: let $A] |
| not | Exclude matches | not: {pattern: safe_call()} |
| has | Must have child | has: {kind: return_statement} |
| inside | Must be in ancestor | inside: {kind: class_body} |
Complete syntax guide: See rule-syntax.md
Language-specific patterns: See common-patterns.md
Bash, C, Cpp, CSharp, Css, Elixir, Go, Haskell, Hcl, Html, Java, JavaScript, Json, Kotlin, Lua, Nix, Php, Python, Ruby, Rust, Scala, Solidity, Swift, Tsx, TypeScript, Yaml
tools
MemPalace local-first AI memory system. Use when setting up persistent memory for Claude Code sessions, mining project files or conversation transcripts, querying past context, configuring MCP tools, managing the knowledge graph, or troubleshooting palace operations.
tools
LangSmith Python SDK — trace, evaluate, and monitor LLM applications. Covers @traceable decorator, trace context manager, Client API, evaluate() / aevaluate(), comparative evaluation, custom evaluators, dataset management, prompt caching, ASGI middleware, and pytest plugin.
development
LangGraph (Python) — build stateful, controllable agent graphs with checkpointing, streaming, persistence, interrupts, fault tolerance, and durable execution. Covers both Graph API (StateGraph) and Functional API (@entrypoint/@task).
development
LangGraph Graph API (Python) — build explicit DAG agent workflows with StateGraph, typed state, nodes, edges, Command routing, Send fan-out, checkpointers, interrupts, and streaming. Use when you need explicit control flow and graph topology.