Skip to content

Commit 80fe29c

Browse files
authored
Unflag codemods for new refs (#319)
* Unflag codemods for new refs * changeset * format
1 parent 0047404 commit 80fe29c

9 files changed

Lines changed: 42 additions & 25 deletions

File tree

.changeset/kind-bugs-teach.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"types-react-codemod": minor
3+
---
4+
5+
Unflag codemods for new refs
6+
7+
Just removing their experimental prefix since we have increased confidence in these changes after seeing their impact internally.
8+
9+
```diff
10+
-experimental-refobject-defaults
11+
+refobject-defaults
12+
-experimental-useRef-required-initial
13+
+useRef-required-initial
14+
```

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ Positionals:
3737
codemod [string] [required] [choices: "context-any", "deprecated-react-child",
3838
"deprecated-react-text", "deprecated-react-type", "deprecated-sfc-element",
3939
"deprecated-sfc", "deprecated-stateless-component",
40-
"deprecated-void-function-component", "experimental-refobject-defaults",
41-
"experimental-useRef-required-initial", "implicit-children", "preset-18",
42-
"preset-19", "scoped-jsx", "useCallback-implicit-any"]
40+
"deprecated-void-function-component", "implicit-children", "preset-18",
41+
"preset-19", "refobject-defaults", "scoped-jsx", "useCallback-implicit-any",
42+
"useRef-required-initial"]
4343
paths [string] [required]
4444

4545
Options:
@@ -71,8 +71,12 @@ The reason being that a false-positive can be reverted easily (assuming you have
7171
- `implicit-children`
7272
- `useCallback-implicit-any`
7373
- `preset-19`
74+
- `deprecated-react-child`
7475
- `deprecated-react-text`
76+
- `deprecated-void-function-component`
77+
- `refobject-defaults`
7578
- `scoped-jsx`
79+
- `useRef-required-initial`
7680

7781
### `preset-18`
7882

@@ -265,7 +269,7 @@ In earlier versions of `@types/react` this codemod would change the typings.
265269
+const Component: React.FunctionComponent = () => {}
266270
```
267271

268-
### `experimental-refobject-defaults`
272+
### `refobject-defaults`
269273

270274
WARNING: This is an experimental codemod to intended for codebases using unpublished types.
271275
Only use if you're using https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64896.
@@ -307,21 +311,18 @@ If the import style doesn't match your preferences, you should set up auto-fixab
307311
+const element: React.JSX.Element = <div />;
308312
```
309313

310-
### `experimental-useRef-required-initial`
311-
312-
WARNING: This is an experimental codemod to intended for codebases using unpublished types.
313-
Only use if you're using https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64920.
314+
### `useRef-required-initial`
314315

315316
`useRef` now always requires an initial value.
316-
Implicit `undefined` is forbidden
317+
Implicit `undefined` is forbidden.
317318

318319
```diff
319320
import * as React from "react";
320321
-React.useRef()
321322
+React.useRef(undefined)
322323
```
323324

324-
#### `experimental-useRef-required-initial` false-negative pattern A
325+
#### `useRef-required-initial` false-negative pattern A
325326

326327
Importing `useRef` via aliased named import will result in the transform being skipped.
327328

bin/__tests__/types-react-codemod.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ describe("types-react-codemod", () => {
2424
codemod [string] [required] [choices: "context-any", "deprecated-react-child",
2525
"deprecated-react-text", "deprecated-react-type", "deprecated-sfc-element",
2626
"deprecated-sfc", "deprecated-stateless-component",
27-
"deprecated-void-function-component", "experimental-refobject-defaults",
28-
"experimental-useRef-required-initial", "implicit-children", "preset-18",
29-
"preset-19", "scoped-jsx", "useCallback-implicit-any"]
27+
"deprecated-void-function-component", "implicit-children", "preset-18",
28+
"preset-19", "refobject-defaults", "scoped-jsx", "useCallback-implicit-any",
29+
"useRef-required-initial"]
3030
paths [string] [required]
3131
3232
Options:

transforms/__tests__/preset-19.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe("preset-19", () => {
88
let deprecatedReactTextTransform;
99
let deprecatedVoidFunctionComponentTransform;
1010
let refobjectDefaultsTransform;
11+
let scopedJSXTransform;
1112
let useRefRequiredInitialTransform;
1213

1314
function applyTransform(source, options = {}) {
@@ -35,11 +36,10 @@ describe("preset-19", () => {
3536
deprecatedVoidFunctionComponentTransform = mockTransform(
3637
"../deprecated-void-function-component",
3738
);
38-
refobjectDefaultsTransform = mockTransform(
39-
"../experimental-refobject-defaults",
40-
);
39+
refobjectDefaultsTransform = mockTransform("../refobject-defaults");
40+
scopedJSXTransform = mockTransform("../scoped-jsx");
4141
useRefRequiredInitialTransform = mockTransform(
42-
"../experimental-useRef-required-initial",
42+
"../useRef-required-initial",
4343
);
4444

4545
preset19Transform = require("../preset-19");
@@ -61,15 +61,17 @@ describe("preset-19", () => {
6161
"deprecated-react-child",
6262
"deprecated-react-text",
6363
"deprecated-void-function-component",
64-
"experimental-refobject-defaults",
65-
"experimental-useRef-required-initial",
64+
"refobject-defaults",
65+
"scoped-jsx",
66+
"useRef-required-initial",
6667
].join(","),
6768
});
6869

6970
expect(deprecatedReactChildTransform).toHaveBeenCalled();
7071
expect(deprecatedReactTextTransform).toHaveBeenCalled();
7172
expect(deprecatedVoidFunctionComponentTransform).toHaveBeenCalled();
7273
expect(refobjectDefaultsTransform).toHaveBeenCalled();
74+
expect(scopedJSXTransform).toHaveBeenCalled();
7375
expect(useRefRequiredInitialTransform).toHaveBeenCalled();
7476
});
7577
});

transforms/__tests__/refobject-defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { describe, expect, test } = require("@jest/globals");
22
const dedent = require("dedent");
33
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
4-
const refobjectDefaultsTransform = require("../experimental-refobject-defaults");
4+
const refobjectDefaultsTransform = require("../refobject-defaults");
55

66
function applyTransform(source, options = {}) {
77
return JscodeshiftTestUtils.applyTransform(

transforms/__tests__/useRef-required-initial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { describe, expect, test } = require("@jest/globals");
22
const dedent = require("dedent");
33
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
4-
const useRefRequiredInitial = require("../experimental-useRef-required-initial");
4+
const useRefRequiredInitial = require("../useRef-required-initial");
55

66
function applyTransform(source, options = {}) {
77
return JscodeshiftTestUtils.applyTransform(useRefRequiredInitial, options, {

transforms/preset-19.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const deprecatedReactChildTransform = require("./deprecated-react-child");
22
const deprecatedReactTextTransform = require("./deprecated-react-text");
33
const deprecatedVoidFunctionComponentTransform = require("./deprecated-void-function-component");
4-
const refobjectDefaultsTransform = require("./experimental-refobject-defaults");
4+
const refobjectDefaultsTransform = require("./refobject-defaults");
55
const scopedJsxTransform = require("./scoped-jsx");
6-
const useRefRequiredInitialTransform = require("./experimental-useRef-required-initial");
6+
const useRefRequiredInitialTransform = require("./useRef-required-initial");
77

88
/**
99
* @type {import('jscodeshift').Transform}
@@ -25,13 +25,13 @@ const transform = (file, api, options) => {
2525
if (transformNames.has("deprecated-void-function-component")) {
2626
transforms.push(deprecatedVoidFunctionComponentTransform);
2727
}
28-
if (transformNames.has("experimental-refobject-defaults")) {
28+
if (transformNames.has("refobject-defaults")) {
2929
transforms.push(refobjectDefaultsTransform);
3030
}
3131
if (transformNames.has("scoped-jsx")) {
3232
transforms.push(scopedJsxTransform);
3333
}
34-
if (transformNames.has("experimental-useRef-required-initial")) {
34+
if (transformNames.has("useRef-required-initial")) {
3535
transforms.push(useRefRequiredInitialTransform);
3636
}
3737

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)