jscodeshift-codemod

Generate jscodeshift codemods for TypeScript and JavaScript codebase transformations.

5|Updated Mar 16, 2019
One-click install
npx skills add https://github.com/third774/dotfiles --skill jscodeshift-codemod
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jscodeshift-codemod
Source: https://github.com/third774/dotfiles/tree/main/.claude/skills/jscodeshift-codemod
Command: npx skills add https://github.com/third774/dotfiles --skill jscodeshift-codemod

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides you through writing jscodeshift codemods for automated code transformations. It helps you create robust codemods for TypeScript/JavaScript migrations, refactor patterns, and React component transformations, including AST navigation, import management, hook migrations, and TS/TSX transformations.

Core Features & Use Cases

  • Guided Codemod Creation: Learn to structure tests first (TDD) and write deterministic codemods.
  • Migration & Refactor Patterns: Automate library upgrades, API changes, and large-scale refactors.
  • React/Hooks Migrations: Handle migrations like useHistory to useNavigate and hook-driven updates.
  • TypeScript/TSX Transformations: Update type annotations and TSX code safely.
  • Operational Guidance: Multi-pass transforms, edge cases, and idempotency considerations.

Quick Start

Run the codemod against a codebase with a TypeScript/JavaScript project:

  • npx jscodeshift -t codemods/jscodeshift-codemod.ts [target] --parser=tsx --extensions=ts,tsx,js,jsx

Frequently Asked Questions about jscodeshift-codemod

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I automate large-scale code migrations across TypeScript and JavaScript projects?

Jscodeshift codemods automate code migrations by parsing your codebase into an abstract syntax tree (AST), applying transformations across multiple files, and outputting updated code. This approach handles TypeScript/JavaScript projects safely and scales to large refactors like library upgrades or API changes without manual edits.

Can I use jscodeshift to transform React hooks like useHistory to useNavigate?

Yes. Jscodeshift codemods excel at React hook migrations by identifying hook calls in your AST, replacing old hooks with new ones, and updating related imports automatically. This handles complex transformations like useHistory to useNavigate across your entire codebase deterministically.

What's the best way to write a codemod that handles edge cases and stays idempotent?

Structure your codemod using test-driven development (TDD): write tests first to capture edge cases, then build transformation logic that checks existing state before modifying code. This ensures your codemod runs safely multiple times without duplicating changes or breaking code in unexpected states.

How do I handle import management when refactoring TypeScript and TSX files?

Jscodeshift codemods navigate the AST to locate and update import statements alongside code transformations. You can add, remove, or rename imports programmatically, ensuring that TypeScript/TSX file refactors maintain correct dependencies and type references across all affected files.

Do I need to understand AST manipulation to write effective codemods?

Yes. Writing effective jscodeshift codemods requires understanding AST navigation—how to query, traverse, and modify code structure. The Skill teaches AST fundamentals through guided codemod creation, enabling you to locate and transform specific code patterns reliably across your project.

When should I use multi-pass transforms in a codemod instead of a single pass?

Use multi-pass transforms when one transformation depends on another or when handling complex interdependencies—for example, updating imports after changing function names, or refactoring nested React components. Multiple passes ensure each transformation completes fully before the next begins, avoiding partial or inconsistent results.