# Build ast-grep Rules for Refactors

AST-based refactors are hard to express with plain text search. This skill helps Claude, Codex, and Claude Code create and refine ast-grep rules.

## Install

```bash
npx skillstore add hylarucoder/ast-grep-rule-crafter
```

## Metadata

- Status: approved
- Slug: hylarucoder-ast-grep-rule-crafter
- Skillstore revision: r1
- Version status: missing
- Tree hash: b58553dd6e6fc0b194e852d6437718fed3b1cdecdeebb6b993dab1bfcbb2835d
- Author: hylarucoder
- GitHub username: hylarucoder
- License: MIT
- Repository: https://github.com/hylarucoder/skills-for-vibe-coder/tree/main/skills/ast-grep-rule-crafter
- Ref: a06681402992ceae98ba04d54cfd4ab004862696
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: filesystem, external\_commands
- Quality score: 75
- Public page: https://skillstore.pages.dev/skills/hylarucoder-ast-grep-rule-crafter
- Manifest: https://skillstore.pages.dev/api/skills/hylarucoder-ast-grep-rule-crafter/manifest

## Capabilities

- Drafts ast-grep YAML rules for search, lint, and rewrite tasks.
- Explains tree-sitter pattern captures and metavariable usage.
- Suggests constraints that reduce false positives in common languages.
- Provides validation steps for scan, debug, and update workflows.
- Uses examples for JavaScript, TypeScript, Python, Go, and Rust.

## Use Cases

- Refactor JavaScript APIs: Create rewrite rules for API changes across a codebase while preserving reviewer control.
- Add Custom Lint Checks: Turn team conventions into AST-aware lint rules with messages and clear match conditions.
- Review Risky Code Patterns: Find unsafe or discouraged patterns with precise rules before manual review.

## Prompt Templates

### Create a Simple Search Rule

```
Create an ast-grep rule for [language] that finds [pattern]. Explain the match and include validation steps.
```

### Reduce False Positives

```
Improve this ast-grep rule for [language] to reduce false positives. Add constraints, test cases, and expected nonmatches.
```

### Design a Rewrite Rule

```
Create an ast-grep rewrite rule that replaces [old API] with [new API]. Include safety checks and review steps.
```

### Plan a Migration Rule Set

```
Design a multi-rule ast-grep migration for [framework]. Cover rule order, rollout strategy, CI use, and manual review points.
```

## Limitations

- Requires the target language, code pattern, and desired outcome.
- Generated rules should be tested before applying fixes.
- Does not verify ast-grep installation or project setup by itself.
- Cannot guarantee zero false positives for every syntax variation.

## Best Practices

- Start with a search-only rule, then add fixes after reviewing matches.
- Test rules on small representative files before project-wide scans.
- Document expected matches, nonmatches, and reviewer assumptions.

## Anti Patterns

- Applying rewrite commands to a full repository before reviewing matches.
- Using broad text-like patterns when node kinds or constraints are available.
- Treating one passing example as proof that the rule is safe.

## Security Audit

- Audited at: 2026-07-06T14:17:52.502\+00:00
- Summary: No malicious intent or prompt injection attempts were found in the reviewed skill files. All 37 static findings are false positives caused by Markdown code fences, inline ast-grep syntax examples, or lint messages rather than executable shell or Ruby code. The skill includes ast-grep commands as documented user examples with fixed arguments.

## Stats

- Views: 160
- Downloads: 9
- Favorites: 1
- Popularity score: 0
