Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

ast-grep

БесплатноБез исполняемых скриптовНе проверен

ast-grep rule writing and usage best practices. This skill should be used when writing, reviewing, or debugging ast-grep rules for code search, linting, and…

pproencaот pproenca★ 231 звезда на GitHub

Об этом скилле

ast-grep Community Best Practices

Comprehensive best practices guide for ast-grep rule writing and usage, maintained by the ast-grep community. Contains 46 rules across 8 categories, prioritized by impact to guide automated rule generation and code transformation.

When to Apply

Reference these guidelines when:

  • Writing new ast-grep rules for linting or search
  • Debugging patterns that don't match expected code
  • Optimizing rule performance for large codebases
  • Setting up ast-grep projects with proper organization
  • Reviewing ast-grep rules for correctness and maintainability

General Workflow

Follow this workflow when creating ast-grep rules for code search:

Step 1: Understand the Query

Clarify what you want to find:

  • Target programming language
  • Edge cases to handle
  • What to include vs exclude

Step 2: Create Example Code

Write a sample code snippet representing the desired match pattern.

Step 3: Write the ast-grep Rule

Choose the right approach:

  • Use pattern for simple structures
  • Use kind with has/inside for complex structures
  • Combine with all, any, or not for compound queries
  • Always use stopBy: end for relational rules (inside, has) to ensure complete search

Step 4: Test the Rule

# Inspect AST structure
ast-grep run --pattern '[code]' --lang [language] --debug-query=ast

# Test inline rule
echo "[code]" | ast-grep scan --inline-rules "[rule]" --stdin

# Test from file
ast-grep scan --rule [file.yml] [path]

Step 5: Search the Codebase

Deploy the validated rule:

# Search with pattern (simple matches)
ast-grep run --pattern '[pattern]' --lang [language] [path]

# Search with rule file (complex queries)
ast-grep scan --rule [file.yml] [path]

# Apply fixes interactively
ast-grep scan --rule [file.yml] --interactive [path]

Quick Tips

  1. Always use stopBy: end - Ensures complete subtree traversal for relational rules
  2. Start simple, add complexity - Begin with patterns, progress to kinds, then relational rules
  3. Debug with AST inspection - Use --debug-query=ast to verify structure matching
  4. Escape in inline rules - Use \$VAR or single quotes for shell commands
  5. Test in playground first - Use https://ast-grep.github.io/playground.html for rapid iteration

Rule Categories by Priority

Priority Category Impact Prefix
1 Pattern Correctness CRITICAL pattern-
2 Meta Variable Usage CRITICAL meta-
3 Rule Composition HIGH compose-
4 Constraint Design HIGH const-
5 Rewrite Correctness MEDIUM-HIGH rewrite-
6 Project Organization MEDIUM org-
7 Performance Optimization MEDIUM perf-
8 Testing & Debugging LOW-MEDIUM test-

Quick Reference

1. Pattern Correctness (CRITICAL)

2. Meta Variable Usage (CRITICAL)

3. Rule Composition (HIGH)

Полный SKILL.md на GitHub

Установить ast-grep в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

AGENTS.mdREADME.mdassets/templates/_template.mdmetadata.jsonreferences/_sections.mdreferences/compose-all-for-and-logic.mdreferences/compose-any-for-or-logic.mdreferences/compose-field-targeting.mdreferences/compose-has-for-children.mdreferences/compose-inside-for-context.mdreferences/compose-matches-for-reuse.mdreferences/compose-not-for-exclusion.mdreferences/compose-precedes-follows.mdreferences/const-kind-filter.mdreferences/const-not-inside-not.mdreferences/const-pattern-constraint.mdreferences/const-post-match-timing.mdreferences/const-regex-filter.mdreferences/meta-multi-match-lazy.mdreferences/meta-named-vs-unnamed.mdreferences/meta-naming-convention.mdreferences/meta-reuse-binding.mdreferences/meta-single-node.mdreferences/meta-underscore-noncapture.mdreferences/org-file-filtering.mdreferences/org-message-clarity.mdreferences/org-project-structure.mdreferences/org-severity-levels.mdreferences/org-unique-rule-ids.mdreferences/pattern-avoid-comments-strings.mdreferences/pattern-context-selector.mdreferences/pattern-debug-ast.mdreferences/pattern-kind-vs-pattern.mdreferences/pattern-language-aware.mdreferences/pattern-nthchild-matching.mdreferences/pattern-range-matching.mdreferences/pattern-strictness-levels.mdreferences/pattern-valid-syntax.mdreferences/perf-avoid-regex-heavy.mdreferences/perf-specific-patterns.md

FAQ

Что делает скилл ast-grep?

ast-grep rule writing and usage best practices. This skill should be used when writing, reviewing, or debugging ast-grep rules for code search, linting, and transformation. Triggers on tasks involving YAML rules, pattern syntax, meta variables, constraints, or code rewriting.

Как установить скилл ast-grep?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл ast-grep запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить ast-grep с