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
parser-
2
AST Traversal Patterns
CRITICAL
traverse-
3
Node Filtering
HIGH
filter-
4
AST Transformation
HIGH
transform-
5
Code Generation
MEDIUM
codegen-
6
Testing Strategies
MEDIUM
test-
7
Runner Optimization
LOW-MEDIUM
runner-
8
Advanced Patterns
LOW
advanced-
Quick Reference
1. Parser Configuration (CRITICAL)
parser-typescript-config - Use correct parser for TypeScript files
parser-flow-annotation - Use Flow parser for Flow-typed code
parser-babel5-compat - Avoid default babel5compat for modern syntax
parser-export-declaration - Export parser from transform module
parser-astexplorer-match - Match AST Explorer parser to jscodeshift parser
2. AST Traversal Patterns (CRITICAL)
traverse-find-specific-type - Use specific node types in find() calls
traverse-two-pass-pattern - Use two-pass pattern for complex transforms
traverse-early-return - Return early when no transformation needed
traverse-find-filter-pattern - Use find() with filter object over filter() chain
traverse-closest-scope - Use closestScope() for scope-aware transforms
traverse-avoid-repeated-find - Avoid repeated find() calls for same node type
3. Node Filtering (HIGH)
filter-path-parent-check - Check parent path before transformation
filter-import-binding - Track import bindings for accurate usage detection
filter-nullish-checks - Add nullish checks before property access
filter-jsx-context - Distinguish JSX context from regular JavaScript
filter-computed-properties - Handle computed property keys in filters
4. AST Transformation (HIGH)
transform-builder-api - Use builder API for creating AST nodes
transform-replacewith-callback - Use replaceWith callback for context-aware transforms
transform-insert-import - Insert imports at correct position
transform-preserve-comments - Preserve comments when replacing nodes
transform-renameto - Use renameTo for variable renaming
transform-remove-unused-imports - Remove unused imports after transformation
5. Code Generation (MEDIUM)
codegen-tosource-options - Configure toSource() for consistent formatting
codegen-preserve-style - Preserve original code style with recast
codegen-template-literals - Use template literals for complex node creation
codegen-print-width - Set appropriate print width for long lines
6. Testing Strategies (MEDIUM)
test-inline-snapshots - Use defineInlineTest for input/output verification
test-negative-cases - Write negative test cases first
test-dry-run-exploration - Use dry run mode for codebase exploration
test-fixture-files - Use fixture files for complex test cases
test-parse-errors - Test for parse error handling
7. Runner Optimization (LOW-MEDIUM)
runner-parallel-workers - Configure worker count for optimal parallelization
runner-ignore-patterns - Use ignore patterns to skip non-source files
runner-extensions-filter - Filter files by extension
runner-batch-processing - Process large codebases in batches
runner-verbose-output - Use verbose output for debugging transforms
8. Advanced Patterns (LOW)
advanced-compose-transforms - Compose multiple transforms into pipelines
advanced-scope-analysis - Use scope analysis for safe variable transforms
advanced-multi-file-state - Share state across files with options
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
1---2name: jscodeshift3description: Facebook/Meta jscodeshift Best Practices4---5# Facebook/Meta jscodeshift Best Practices67Comprehensive 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.89## When to Apply1011Reference these guidelines when:12- Writing new jscodeshift codemods for code migrations13- Debugging transform failures or unexpected behavior14- Optimizing codemod performance on large codebases15- Reviewing codemod code for correctness16- Testing codemods for edge cases and regressions1718## Rule Categories by Priority1920| Priority | Category | Impact | Prefix |21|----------|----------|--------|--------|22| 1 | Parser Configuration | CRITICAL | `parser-` |23| 2 | AST Traversal Patterns | CRITICAL | `traverse-` |24| 3 | Node Filtering | HIGH | `filter-` |25| 4 | AST Transformation | HIGH | `transform-` |26| 5 | Code Generation | MEDIUM | `codegen-` |27| 6 | Testing Strategies | MEDIUM | `test-` |28| 7 | Runner Optimization | LOW-MEDIUM | `runner-` |29| 8 | Advanced Patterns | LOW | `advanced-` |3031## Quick Reference3233### 1. Parser Configuration (CRITICAL)3435- [`parser-typescript-config`](references/parser-typescript-config.md) - Use correct parser for TypeScript files36- [`parser-flow-annotation`](references/parser-flow-annotation.md) - Use Flow parser for Flow-typed code37- [`parser-babel5-compat`](references/parser-babel5-compat.md) - Avoid default babel5compat for modern syntax38- [`parser-export-declaration`](references/parser-export-declaration.md) - Export parser from transform module39- [`parser-astexplorer-match`](references/parser-astexplorer-match.md) - Match AST Explorer parser to jscodeshift parser4041### 2. AST Traversal Patterns (CRITICAL)4243- [`traverse-find-specific-type`](references/traverse-find-specific-type.md) - Use specific node types in find() calls44- [`traverse-two-pass-pattern`](references/traverse-two-pass-pattern.md) - Use two-pass pattern for complex transforms45- [`traverse-early-return`](references/traverse-early-return.md) - Return early when no transformation needed46- [`traverse-find-filter-pattern`](references/traverse-find-filter-pattern.md) - Use find() with filter object over filter() chain47- [`traverse-closest-scope`](references/traverse-closest-scope.md) - Use closestScope() for scope-aware transforms48- [`traverse-avoid-repeated-find`](references/traverse-avoid-repeated-find.md) - Avoid repeated find() calls for same node type4950### 3. Node Filtering (HIGH)5152- [`filter-path-parent-check`](references/filter-path-parent-check.md) - Check parent path before transformation53- [`filter-import-binding`](references/filter-import-binding.md) - Track import bindings for accurate usage detection54- [`filter-nullish-checks`](references/filter-nullish-checks.md) - Add nullish checks before property access55- [`filter-jsx-context`](references/filter-jsx-context.md) - Distinguish JSX context from regular JavaScript56- [`filter-computed-properties`](references/filter-computed-properties.md) - Handle computed property keys in filters5758### 4. AST Transformation (HIGH)5960- [`transform-builder-api`](references/transform-builder-api.md) - Use builder API for creating AST nodes61- [`transform-replacewith-callback`](references/transform-replacewith-callback.md) - Use replaceWith callback for context-aware transforms62- [`transform-insert-import`](references/transform-insert-import.md) - Insert imports at correct position63- [`transform-preserve-comments`](references/transform-preserve-comments.md) - Preserve comments when replacing nodes64- [`transform-renameto`](references/transform-renameto.md) - Use renameTo for variable renaming65- [`transform-remove-unused-imports`](references/transform-remove-unused-imports.md) - Remove unused imports after transformation6667### 5. Code Generation (MEDIUM)6869- [`codegen-tosource-options`](references/codegen-tosource-options.md) - Configure toSource() for consistent formatting70- [`codegen-preserve-style`](references/codegen-preserve-style.md) - Preserve original code style with recast71- [`codegen-template-literals`](references/codegen-template-literals.md) - Use template literals for complex node creation72- [`codegen-print-width`](references/codegen-print-width.md) - Set appropriate print width for long lines7374### 6. Testing Strategies (MEDIUM)7576- [`test-inline-snapshots`](references/test-inline-snapshots.md) - Use defineInlineTest for input/output verification77- [`test-negative-cases`](references/test-negative-cases.md) - Write negative test cases first78- [`test-dry-run-exploration`](references/test-dry-run-exploration.md) - Use dry run mode for codebase exploration79- [`test-fixture-files`](references/test-fixture-files.md) - Use fixture files for complex test cases80- [`test-parse-errors`](references/test-parse-errors.md) - Test for parse error handling8182### 7. Runner Optimization (LOW-MEDIUM)8384- [`runner-parallel-workers`](references/runner-parallel-workers.md) - Configure worker count for optimal parallelization85- [`runner-ignore-patterns`](references/runner-ignore-patterns.md) - Use ignore patterns to skip non-source files86- [`runner-extensions-filter`](references/runner-extensions-filter.md) - Filter files by extension87- [`runner-batch-processing`](references/runner-batch-processing.md) - Process large codebases in batches88- [`runner-verbose-output`](references/runner-verbose-output.md) - Use verbose output for debugging transforms8990### 8. Advanced Patterns (LOW)9192- [`advanced-compose-transforms`](references/advanced-compose-transforms.md) - Compose multiple transforms into pipelines93- [`advanced-scope-analysis`](references/advanced-scope-analysis.md) - Use scope analysis for safe variable transforms94- [`advanced-multi-file-state`](references/advanced-multi-file-state.md) - Share state across files with options95- [`advanced-custom-collections`](references/advanced-custom-collections.md) - Create custom collection methods9697## How to Use9899Read individual reference files for detailed explanations and code examples:100101- [Section definitions](references/_sections.md) - Category structure and impact levels102- [Rule template](assets/templates/_template.md) - Template for adding new rules103104## Full Compiled Document105106For a single comprehensive document containing all rules, see [AGENTS.md](AGENTS.md).107108## Reference Files109110| File | Description |111|------|-------------|112| [AGENTS.md](AGENTS.md) | Complete compiled guide with all rules |113| [references/_sections.md](references/_sections.md) | Category definitions and ordering |114| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |115| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/jscodeshift in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Facebook/Meta jscodeshift Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.