install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/codemod" ~/.claude/skills/comeonoliver-skillshub-codemod && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/codemod/SKILL.mdsource content
Codemod Best Practices
Comprehensive best practices guide for Codemod (JSSG, ast-grep, workflows), designed for AI agents and LLMs. Contains 48 rules across 11 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new codemods with JSSG or ast-grep
- Designing workflow configurations for migrations
- Debugging pattern matching or AST traversal issues
- Reviewing codemod code for performance and safety
- Setting up test fixtures for transform validation
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | AST Understanding | CRITICAL | |
| 2 | Pattern Efficiency | CRITICAL | |
| 3 | Parsing Strategy | CRITICAL | |
| 4 | Node Traversal | HIGH | |
| 5 | Semantic Analysis | HIGH | |
| 6 | Edit Operations | MEDIUM-HIGH | |
| 7 | Workflow Design | MEDIUM-HIGH | |
| 8 | Testing Strategy | MEDIUM | |
| 9 | State Management | MEDIUM | |
| 10 | Security and Capabilities | LOW-MEDIUM | |
| 11 | Package Structure | LOW | |
Quick Reference
1. AST Understanding (CRITICAL)
- Use AST Explorer before writing patternsast-explore-before-writing
- Understand named vs anonymous nodesast-understand-named-vs-anonymous
- Use kind constraint for precisionast-use-kind-for-precision
- Use field access for structural queriesast-field-access-for-structure
- Check null before property accessast-check-null-before-access
2. Pattern Efficiency (CRITICAL)
- Use meta variables for flexible matchingpattern-use-meta-variables
- Avoid overly generic patternspattern-avoid-overly-generic
- Combine patterns with rule operatorspattern-combine-with-rules
- Use constraints for reusable matching logicpattern-use-constraints
- Use relational patterns for contextpattern-use-relational-patterns
- Ensure patterns are idempotentpattern-ensure-idempotency
3. Parsing Strategy (CRITICAL)
- Select the correct parser for file typeparse-select-correct-parser
- Handle embedded languages with parseAsyncparse-handle-embedded-languages
- Provide context for ambiguous patternsparse-provide-pattern-context
- Early return for non-applicable filesparse-early-return-non-applicable
4. Node Traversal (HIGH)
- Use find() for single match, findAll() for multipletraverse-use-find-vs-findall
- Collect multiple patterns in single traversaltraverse-single-pass-collection
- Use stopBy to control traversal depthtraverse-use-stopby-for-depth
- Use sibling navigation efficientlytraverse-use-siblings-efficiently
- Cache repeated node lookupstraverse-cache-repeated-lookups
5. Semantic Analysis (HIGH)
- Use file scope semantic analysis firstsemantic-use-file-scope-first
- Handle null semantic analysis resultssemantic-check-null-results
- Verify file ownership before cross-file editssemantic-verify-file-ownership
- Cache semantic analysis resultssemantic-cache-cross-file-results
6. Edit Operations (MEDIUM-HIGH)
- Batch edits before committingedit-batch-before-commit
- Preserve surrounding formatting in editsedit-preserve-formatting
- Handle overlapping edit rangesedit-handle-overlapping-ranges
- Use flatMap for conditional editsedit-use-flatmap-for-conditional
- Add imports at correct positionedit-add-imports-correctly
7. Workflow Design (MEDIUM-HIGH)
- Order nodes by dependencyworkflow-order-nodes-by-dependency
- Use matrix strategy for parallelismworkflow-use-matrix-for-parallelism
- Use manual gates for critical stepsworkflow-use-manual-gates
- Validate workflows before runningworkflow-validate-before-run
- Use conditional steps for dynamic workflowsworkflow-use-conditional-steps
8. Testing Strategy (MEDIUM)
- Use input/expected fixture pairstest-use-fixture-pairs
- Cover edge cases in test fixturestest-cover-edge-cases
- Choose appropriate test strictness leveltest-use-strictness-levels
- Update test fixtures intentionallytest-update-fixtures-intentionally
- Test on file subset before full runtest-run-on-subset-first
9. State Management (MEDIUM)
- Use state for resumable migrationsstate-use-for-resumability
- Make transforms idempotent for safe rerunsstate-make-transforms-idempotent
- Log progress for long-running migrationsstate-log-progress-for-observability
10. Security and Capabilities (LOW-MEDIUM)
- Minimize requested capabilitiessecurity-minimize-capabilities
- Validate external inputs before usesecurity-validate-external-inputs
- Review third-party codemods before runningsecurity-review-before-running-third-party
11. Package Structure (LOW)
- Use semantic versioning for packagespkg-use-semantic-versioning
- Write descriptive package metadatapkg-write-descriptive-metadata
- Organize package by conventionpkg-organize-by-convention
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Full Compiled Document
For a complete guide with all rules expanded, see AGENTS.md.