Skip to content

Commit 2e3b434

Browse files
committed
update docs
1 parent b6063dd commit 2e3b434

4 files changed

Lines changed: 103 additions & 64 deletions

File tree

LEGACY.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
# Legacy Codemods
22

3-
This branch keeps the non-high-priority `react-codemod` transforms as a legacy jscodeshift snapshot under [`codemods/legacy/transforms/`](./codemods/legacy/transforms/).
3+
The following jscodeshift-based codemods from the original [`react-codemod`](https://github.com/reactjs/react-codemod) project are available under [`codemods/legacy/transforms/`](./codemods/legacy/transforms/).
44

5-
The legacy snapshot is preserved for source reference, upstream-style tests, and branch preview parity with the structure of `reactjs/react-codemod`.
5+
These codemods are preserved for compatibility and can be run directly with jscodeshift.
66

7-
## Legacy Catalog
7+
## Catalog
88

9-
- [`create-element-to-jsx`](./codemods/legacy/transforms/create-element-to-jsx.js)
10-
- [`error-boundaries`](./codemods/legacy/transforms/error-boundaries.js)
11-
- [`findDOMNode`](./codemods/legacy/transforms/findDOMNode.js)
12-
- [`manual-bind-to-arrow`](./codemods/legacy/transforms/manual-bind-to-arrow.js)
13-
- [`pure-component`](./codemods/legacy/transforms/pure-component.js)
14-
- [`pure-render-mixin`](./codemods/legacy/transforms/pure-render-mixin.js)
15-
- [`React-DOM-to-react-dom-factories`](./codemods/legacy/transforms/React-DOM-to-react-dom-factories.js)
16-
- [`ReactNative-View-propTypes`](./codemods/legacy/transforms/ReactNative-View-propTypes.js)
17-
- [`react-to-react-dom`](./codemods/legacy/transforms/react-to-react-dom.js)
18-
- [`remove-context-provider`](./codemods/legacy/transforms/remove-context-provider.ts)
19-
- [`remove-forward-ref`](./codemods/legacy/transforms/remove-forward-ref.ts)
20-
- [`rename-unsafe-lifecycles`](./codemods/legacy/transforms/rename-unsafe-lifecycles.js)
21-
- [`sort-comp`](./codemods/legacy/transforms/sort-comp.js)
22-
- [`update-react-imports`](./codemods/legacy/transforms/update-react-imports.js)
23-
- [`class`](./codemods/legacy/transforms/class.js)
9+
- [`create-element-to-jsx`](./codemods/legacy/transforms/create-element-to-jsx.js) — convert `React.createElement` calls to JSX
10+
- [`error-boundaries`](./codemods/legacy/transforms/error-boundaries.js) — rename `unstable_handleError` to `componentDidCatch`
11+
- [`findDOMNode`](./codemods/legacy/transforms/findDOMNode.js) — update `getDOMNode()` calls to `React.findDOMNode()`
12+
- [`manual-bind-to-arrow`](./codemods/legacy/transforms/manual-bind-to-arrow.js) — convert manual function bindings to arrow functions
13+
- [`pure-component`](./codemods/legacy/transforms/pure-component.js) — convert render-only class components to functional components
14+
- [`pure-render-mixin`](./codemods/legacy/transforms/pure-render-mixin.js) — remove `PureRenderMixin` and inline `shouldComponentUpdate`
15+
- [`React-DOM-to-react-dom-factories`](./codemods/legacy/transforms/React-DOM-to-react-dom-factories.js) — convert `React.DOM.div(...)` to `React.createElement('div', ...)`
16+
- [`ReactNative-View-propTypes`](./codemods/legacy/transforms/ReactNative-View-propTypes.js) — replace `View.propTypes` with `ViewPropTypes`
17+
- [`react-to-react-dom`](./codemods/legacy/transforms/react-to-react-dom.js) — update code for the `react` / `react-dom` package split
18+
- [`remove-context-provider`](./codemods/legacy/transforms/remove-context-provider.ts) — convert `Context.Provider` elements to `Context`
19+
- [`remove-forward-ref`](./codemods/legacy/transforms/remove-forward-ref.ts) — remove usages of `forwardRef`
20+
- [`rename-unsafe-lifecycles`](./codemods/legacy/transforms/rename-unsafe-lifecycles.js) — add `UNSAFE_` prefix to deprecated lifecycle hooks
21+
- [`sort-comp`](./codemods/legacy/transforms/sort-comp.js) — enforce React component method ordering
22+
- [`update-react-imports`](./codemods/legacy/transforms/update-react-imports.js) — remove redundant React imports and convert to named imports
23+
- [`class`](./codemods/legacy/transforms/class.js) — convert `React.createClass` calls to ES6 classes
2424

25-
## Notes
25+
## Running
2626

27-
- The 6 promoted JSSG transforms are not duplicated in `codemods/legacy/`.
28-
- This preview branch does not claim that legacy transforms can be run through Codemod Registry.
29-
- The legacy snapshot keeps the full upstream-style test corpus in `codemods/legacy/transforms/__tests__`.
30-
- The preview branch CI runs the compatible legacy subset under the current preview runtime:
31-
32-
```bash
33-
pnpm run test:legacy
34-
```
35-
36-
- To run the full legacy snapshot test corpus manually from `codemods/legacy/`:
27+
From `codemods/legacy/`:
3728

3829
```bash
30+
pnpm install
3931
pnpm test
4032
```

PARITY_STATUS.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
# Legacy Parity Status
1+
# Parity Status
22

33
Last updated: 2026-04-15
44

55
Status meanings:
66

7-
- `Certified`: replacement-grade rollout confidence. Strict/default package tests are green, public test posture is portable, and there are no known rollout-blocking logic gaps versus the legacy jscodeshift codemod. `Certified` may include intentional safe extensions on legacy-unsupported edge cases, as long as intentional legacy behavior remains unbroken.
8-
- `Legacy Snapshot`: preserved as upstream jscodeshift source and tests on this branch, but not promoted as part of the active JSSG replacement surface.
7+
- `Certified`: replacement-grade confidence. Tests are green, public test posture is portable, and there are no known logic gaps versus the original jscodeshift codemod. May include safe extensions on edge cases the original did not handle, as long as original behavior remains unbroken.
8+
- `Legacy`: available as a jscodeshift codemod under `codemods/legacy/`. Not yet ported to JSSG.
99

10-
## Active JSSG Surface
10+
## JSSG Codemods
1111

12-
These are the only codemods promoted as active replacements on this branch.
13-
14-
| Codemod | Legacy Source | Status | Notes |
12+
| Codemod | Original Source | Status | Notes |
1513
| --- | --- | --- | --- |
16-
| `replace-use-form-state` | `replace-use-form-state.ts` | `Certified` | Legacy fixture surface plus added multi-import regression coverage are green. Collection-wide replacement on matching `react-dom` imports fixes a real parity gap, and the broader multi-import handling is treated as an acceptable safe extension where legacy only partially migrated files. |
17-
| `replace-act-import` | `replace-act-import.ts` | `Certified` | Legacy fixture surface plus added multi-import regression coverage. This closes a real parity gap, and the mixed test-utils partial-removal path is an acceptable safe extension that does not break intentional legacy behavior. |
18-
| `replace-string-ref` | `replace-string-ref.ts` | `Certified` | Legacy fixture surface plus added namespace/default-export/multi-ref coverage are green, and the direct-superclass guard restores the intended direct-superclass behavior by avoiding the prior mixin false positive. |
19-
| `replace-reactdom-render` | `replace-reactdom-render.ts` | `Certified` | Legacy fixtures plus added multi-alias regression coverage are green. The extra multi-alias handling is an acceptable safe extension over legacy implementation limits; it preserves intentional legacy behavior while covering additional valid cases. |
20-
| `react-proptypes-to-prop-types` | `React-PropTypes-to-prop-types.js` | `Certified` | Full legacy fixture surface is green, targeted mixed-import validation is aligned, and no JSSG-specific rollout blocker was found in the audit. No additional extension beyond the legacy behavior is currently relied on for certification. |
21-
| `use-context-hook` | `use-context-hook.ts` | `Certified` | Legacy fixture surface plus added multi-import regression coverage are green. The multi-import handling goes beyond the legacy implementation, but it is treated as an acceptable safe extension because it preserves intentional legacy behavior while covering additional valid cases. |
14+
| `replace-use-form-state` | `replace-use-form-state.ts` | `Certified` | Full fixture coverage plus multi-import regression tests are green. Collection-wide replacement on matching `react-dom` imports fixes a real parity gap. |
15+
| `replace-act-import` | `replace-act-import.ts` | `Certified` | Full fixture coverage plus multi-import regression tests. Mixed test-utils partial-removal path is a safe extension. |
16+
| `replace-string-ref` | `replace-string-ref.ts` | `Certified` | Full fixture coverage plus namespace/default-export/multi-ref tests are green. Direct-superclass guard restores intended behavior. |
17+
| `replace-reactdom-render` | `replace-reactdom-render.ts` | `Certified` | Full fixture coverage plus multi-alias regression tests are green. |
18+
| `react-proptypes-to-prop-types` | `React-PropTypes-to-prop-types.js` | `Certified` | Full original fixture surface is green. No JSSG-specific rollout blocker found. |
19+
| `use-context-hook` | `use-context-hook.ts` | `Certified` | Full fixture coverage plus multi-import regression tests are green. |
2220

23-
## Legacy Snapshot Surface
21+
## Legacy Codemods
2422

25-
These codemods remain available only as an upstream jscodeshift snapshot under [`codemods/legacy/transforms/`](./codemods/legacy/transforms/):
23+
These codemods are available as jscodeshift transforms under [`codemods/legacy/transforms/`](./codemods/legacy/transforms/):
2624

2725
- `class`
2826
- `create-element-to-jsx`

README.md

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,61 @@
1-
# React Codemods Preview
1+
# React Codemods
22

3-
This branch is a React-facing preview of how this repo should look as a replacement-style home for `react-codemod`.
3+
This repository contains a collection of codemods to help update React apps.
44

5-
It promotes 6 audited JSSG codemods as the active surface and preserves the remaining upstream jscodeshift codemods as a legacy snapshot.
5+
All codemods are free and open source, with the source code available in this repository.
66

7-
## Active JSSG Transforms
7+
## Usage
88

9-
These transforms are the active replacement surface on this branch. They are source-first JSSG codemods and are not described here as Codemod Registry entries unless they are actually published.
9+
Run a codemod from this directory using the [Codemod CLI](https://go.codemod.com/cli-docs):
1010

11-
- [`use-context-hook`](./codemods/jssg/use-context-hook/) — replace `useContext` usage with `use`
12-
- [`replace-act-import`](./codemods/jssg/replace-act-import/) — move `act` from `react-dom/test-utils` to `react`
13-
- [`replace-string-ref`](./codemods/jssg/replace-string-ref/) — replace deprecated string refs with callback refs
14-
- [`replace-use-form-state`](./codemods/jssg/replace-use-form-state/) — rename `useFormState` to `useActionState`
15-
- [`replace-reactdom-render`](./codemods/jssg/replace-reactdom-render/) — replace `ReactDOM.render` with `createRoot(...).render(...)`
16-
- [`react-proptypes-to-prop-types`](./codemods/jssg/react-proptypes-to-prop-types/) — replace `React.PropTypes` with `prop-types`
11+
```bash
12+
pnpm dlx codemod@latest jssg run --language tsx --target <path> ./codemods/jssg/<transform>/scripts/codemod.ts
13+
```
14+
15+
- `<transform>` — name of the codemod (see available codemods below)
16+
- `<path>` — files or directory to transform
17+
18+
## Available Codemods
19+
20+
### `use-context-hook`
21+
22+
Replaces usages of `React.useContext(...)` with `React.use(...)`.
23+
24+
See [`use-context-hook`](./codemods/jssg/use-context-hook/) for details.
25+
26+
### `replace-act-import`
27+
28+
Updates `act` import path from `react-dom/test-utils` to `react`.
29+
30+
See [`replace-act-import`](./codemods/jssg/replace-act-import/) for details.
31+
32+
### `replace-string-ref`
33+
34+
Replaces deprecated string refs with callback refs.
35+
36+
See [`replace-string-ref`](./codemods/jssg/replace-string-ref/) for details.
37+
38+
### `replace-use-form-state`
39+
40+
Replaces usages of `useFormState()` with `useActionState()`.
1741

18-
## Legacy Codemods
42+
See [`replace-use-form-state`](./codemods/jssg/replace-use-form-state/) for details.
1943

20-
All non-priority transforms are preserved as an upstream-style legacy jscodeshift snapshot under [`codemods/legacy/`](./codemods/legacy/).
44+
### `replace-reactdom-render`
2145

22-
See [LEGACY.md](./LEGACY.md) for the legacy catalog and testing notes.
46+
Replaces usages of `ReactDOM.render()` with `createRoot(node).render()`.
47+
48+
See [`replace-reactdom-render`](./codemods/jssg/replace-reactdom-render/) for details.
49+
50+
### `react-proptypes-to-prop-types`
51+
52+
Replaces `React.PropTypes` references with the `prop-types` package and adds the appropriate import statement.
53+
54+
See [`react-proptypes-to-prop-types`](./codemods/jssg/react-proptypes-to-prop-types/) for details.
55+
56+
### Legacy Codemods
57+
58+
Additional jscodeshift-based codemods from the original `react-codemod` project are available under [`codemods/legacy/`](./codemods/legacy/). See [LEGACY.md](./LEGACY.md) for the full catalog.
2359

2460
## Development
2561

@@ -28,15 +64,28 @@ pnpm install
2864
pnpm run ci
2965
```
3066

31-
Run active JSSG checks only:
67+
Run tests:
68+
69+
```bash
70+
pnpm test
71+
```
72+
73+
Run type checking:
3274

3375
```bash
34-
pnpm run test:active
35-
pnpm run check-types:active
76+
pnpm run check-types
3677
```
3778

38-
Run the legacy snapshot test harness:
79+
Run legacy codemod tests:
3980

4081
```bash
4182
pnpm run test:legacy
4283
```
84+
85+
## Support and Contributing
86+
87+
If you want to contribute, you're welcome to submit a pull request.
88+
89+
## License
90+
91+
react-codemod is [MIT licensed](./LICENSE).

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "react-codemod-preview",
2+
"name": "react-codemod",
33
"version": "0.1.0",
44
"private": true,
5-
"description": "Preview repo surface for React codemods with active JSSG replacements and a legacy snapshot",
5+
"description": "A collection of codemods to help update React apps",
66
"type": "module",
77
"scripts": {
88
"lint": "node ./scripts/validate-docs.mjs",

0 commit comments

Comments
 (0)