Agent skill · software engineering · aiskillstore
ast-grep-rule-crafter
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.
Why this skill is useful
Provides specific YAML-based AST matching patterns and commands for code linting and rewriting that the AI wouldn't reliably generate on its own.
What it needs
Requires ast-grep installed locally. About 2k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.
What this skill does
ast-grep Rule Crafter 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. Quick Start Project Configuration 项目级扫描需要 sgconfig.yml 配置文件: 典型项目结构: 运行项目扫描: 注意: ast-grep scan 命令必须有 sgconfig.yml,而 ast-grep run -p 可单独使用。 Rule Workflow Lint Rule (常见) 只检查不修复,用于 CI/编辑器提示: 验证: Rewrite Rule (可选) 需要自动修复时添加 fix: 应用修复: 开发流程 调试 AST 结构: Essential Syntax 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) Core Rules Quick Reference Type Purpose Example ------ --------- --------- pattern Match code structure pattern: if ($COND) {} kind Match AST node type kind: functiondeclaration 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: safecall()} has Must have child has: {kind: returnstatement} inside Must be in ancestor inside: {kind: classbody} Detailed References Complete syntax guide: See references/rule-syntax.md Atomic rules (pattern, kind, regex, nthChild, range) Composite rules (all, any, not, matches) Relational rules (has, inside, follows, precedes) Transform and fixConfig Language-specific patterns: See references/common-patterns.md JavaScript/TypeScript examples Python examples Go and Rust examples Supported Languages 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
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills aiskillstore/ast-grep-rule-crafter