Iifabrish

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

Rename OldThing to NewThing

transformationmigrationreactjsxtsx
Public
0 executions

Run locally

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

to:

tsx

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

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

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.