Claude-skill-registry jscodeshift
jscodeshift codemod development best practices from Facebook/Meta. This skill should be used when writing, reviewing, or debugging jscodeshift codemods. Triggers on tasks involving AST transformation, code migration, automated refactoring, or codemod development.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/jscodeshift" ~/.claude/skills/majiayu000-claude-skill-registry-jscodeshift && rm -rf "$T"
skills/data/jscodeshift/SKILL.mdFacebook/Meta jscodeshift Best Practices
Comprehensive best practices guide for jscodeshift codemod development, designed for AI agents and LLMs. Contains 40 rules across 8 categories, prioritized by impact from critical (parser configuration, AST traversal) to incremental (advanced patterns). Each rule includes detailed explanations, real-world examples, and specific impact metrics.
When to Apply
Reference these guidelines when:
- Writing new jscodeshift codemods for code migrations
- Debugging transform failures or unexpected behavior
- Optimizing codemod performance on large codebases
- Reviewing codemod code for correctness
- Testing codemods for edge cases and regressions
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Parser Configuration | CRITICAL | |
| 2 | AST Traversal Patterns | CRITICAL | |
| 3 | Node Filtering | HIGH | |
| 4 | AST Transformation | HIGH | |
| 5 | Code Generation | MEDIUM | |
| 6 | Testing Strategies | MEDIUM | |
| 7 | Runner Optimization | LOW-MEDIUM | |
| 8 | Advanced Patterns | LOW | |
Quick Reference
1. Parser Configuration (CRITICAL)
- Use correct parser for TypeScript filesparser-typescript-config
- Use Flow parser for Flow-typed codeparser-flow-annotation
- Avoid default babel5compat for modern syntaxparser-babel5-compat
- Export parser from transform moduleparser-export-declaration
- Match AST Explorer parser to jscodeshift parserparser-astexplorer-match
2. AST Traversal Patterns (CRITICAL)
- Use specific node types in find() callstraverse-find-specific-type
- Use two-pass pattern for complex transformstraverse-two-pass-pattern
- Return early when no transformation neededtraverse-early-return
- Use find() with filter object over filter() chaintraverse-find-filter-pattern
- Use closestScope() for scope-aware transformstraverse-closest-scope
- Avoid repeated find() calls for same node typetraverse-avoid-repeated-find
3. Node Filtering (HIGH)
- Check parent path before transformationfilter-path-parent-check
- Track import bindings for accurate usage detectionfilter-import-binding
- Add nullish checks before property accessfilter-nullish-checks
- Distinguish JSX context from regular JavaScriptfilter-jsx-context
- Handle computed property keys in filtersfilter-computed-properties
4. AST Transformation (HIGH)
- Use builder API for creating AST nodestransform-builder-api
- Use replaceWith callback for context-aware transformstransform-replacewith-callback
- Insert imports at correct positiontransform-insert-import
- Preserve comments when replacing nodestransform-preserve-comments
- Use renameTo for variable renamingtransform-renameto
- Remove unused imports after transformationtransform-remove-unused-imports
5. Code Generation (MEDIUM)
- Configure toSource() for consistent formattingcodegen-tosource-options
- Preserve original code style with recastcodegen-preserve-style
- Use template literals for complex node creationcodegen-template-literals
- Set appropriate print width for long linescodegen-print-width
6. Testing Strategies (MEDIUM)
- Use defineInlineTest for input/output verificationtest-inline-snapshots
- Write negative test cases firsttest-negative-cases
- Use dry run mode for codebase explorationtest-dry-run-exploration
- Use fixture files for complex test casestest-fixture-files
- Test for parse error handlingtest-parse-errors
7. Runner Optimization (LOW-MEDIUM)
- Configure worker count for optimal parallelizationrunner-parallel-workers
- Use ignore patterns to skip non-source filesrunner-ignore-patterns
- Filter files by extensionrunner-extensions-filter
- Process large codebases in batchesrunner-batch-processing
- Use verbose output for debugging transformsrunner-verbose-output
8. Advanced Patterns (LOW)
- Compose multiple transforms into pipelinesadvanced-compose-transforms
- Use scope analysis for safe variable transformsadvanced-scope-analysis
- Share state across files with optionsadvanced-multi-file-state
- Create custom collection methodsadvanced-custom-collections
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 single comprehensive document containing all rules, see AGENTS.md.
Reference Files
| File | Description |
|---|---|
| AGENTS.md | Complete compiled guide with all rules |
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |