Registry
Iifabrish avatar

rename-oldthing-to-newthing-brisk-spark-1shi

Rename OldThing to NewThing

ifabrish0 executions

  • transformation
  • migration
  • react
  • jsx
  • tsx
Connect a repo
npx codemod rename-oldthing-to-newthing-brisk-spark-1shi

rename-oldthing-to-newthing-brisk-spark-1shi

Rename OldThing JSX usages to NewThing and rename the bar prop to count for the migrated component.

What It Changes

This codemod targets TypeScript React / TSX code and rewrites these patterns:

tsx
<OldThing foo="x" bar={1} />

to:

tsx
<NewThing foo="x" count={1} />

Supported behavior:

  • Renames <OldThing ...> to <NewThing ...>
  • Renames </OldThing> to </NewThing>
  • Renames bar={...} to count={...} only on migrated OldThing elements
  • Preserves unrelated props, prop ordering, and surrounding formatting
  • Renames a direct named import like import { OldThing } from "..." to import { NewThing } from "..." when that update is unambiguous
  • Renames the imported symbol in import { OldThing as Alias } from "..." to NewThing only when there is no conflicting local NewThing binding from imports

Conservative behavior:

  • If a migrated element already has a count prop, the codemod leaves bar unchanged to avoid creating duplicate props
  • If import updates look ambiguous or would create a conflicting NewThing import binding, the codemod leaves imports conservative
  • Namespace-qualified JSX and other ambiguous component indirections are intentionally not guessed

Workflow

The package ships as a two-step workflow:

  1. An AST-based TSX codemod applies the deterministic JSX and import rename.
  2. An optional AI step named AI review and cleanup reviews the diff for ambiguous import updates or duplicate prop cleanup.

Workflow Parameter

  • runAiCleanup (boolean, default true): enables the AI review and cleanup step

Usage

bash
# Run locally against a target repository
npx codemod workflow run -w . -t /path/to/repo

# Disable the optional AI cleanup step
npx codemod workflow run -w . -t /path/to/repo --param runAiCleanup=false

The workflow scans **/*.{ts,tsx,mts,cts} and excludes node_modules, dist, and build directories.

Test Coverage

Fixtures cover:

  • Self-closing JSX migration
  • Paired opening/closing tag migration
  • Preservation of unrelated props
  • Direct named import updates when unambiguous
  • Conservative duplicate-prop handling when both bar and count are present
  • Conservative import handling when NewThing is already imported

Development

bash
pnpm test
pnpm exec tsc --noEmit
npx codemod workflow validate -w workflow.yaml

License

MIT

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.