Skip to content

Commit

Permalink
Unflag codemods for new refs (#319)
Browse files Browse the repository at this point in the history
* Unflag codemods for new refs

* changeset

* format
  • Loading branch information
eps1lon committed Dec 6, 2023
1 parent 0047404 commit 80fe29c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 25 deletions.
14 changes: 14 additions & 0 deletions .changeset/kind-bugs-teach.md
@@ -0,0 +1,14 @@
---
"types-react-codemod": minor
---

Unflag codemods for new refs

Just removing their experimental prefix since we have increased confidence in these changes after seeing their impact internally.

```diff
-experimental-refobject-defaults
+refobject-defaults
-experimental-useRef-required-initial
+useRef-required-initial
```
21 changes: 11 additions & 10 deletions README.md
Expand Up @@ -37,9 +37,9 @@ Positionals:
codemod [string] [required] [choices: "context-any", "deprecated-react-child",
"deprecated-react-text", "deprecated-react-type", "deprecated-sfc-element",
"deprecated-sfc", "deprecated-stateless-component",
"deprecated-void-function-component", "experimental-refobject-defaults",
"experimental-useRef-required-initial", "implicit-children", "preset-18",
"preset-19", "scoped-jsx", "useCallback-implicit-any"]
"deprecated-void-function-component", "implicit-children", "preset-18",
"preset-19", "refobject-defaults", "scoped-jsx", "useCallback-implicit-any",
"useRef-required-initial"]
paths [string] [required]

Options:
Expand Down Expand Up @@ -71,8 +71,12 @@ The reason being that a false-positive can be reverted easily (assuming you have
- `implicit-children`
- `useCallback-implicit-any`
- `preset-19`
- `deprecated-react-child`
- `deprecated-react-text`
- `deprecated-void-function-component`
- `refobject-defaults`
- `scoped-jsx`
- `useRef-required-initial`

### `preset-18`

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

### `experimental-refobject-defaults`
### `refobject-defaults`

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

### `experimental-useRef-required-initial`

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

`useRef` now always requires an initial value.
Implicit `undefined` is forbidden
Implicit `undefined` is forbidden.

```diff
import * as React from "react";
-React.useRef()
+React.useRef(undefined)
```

#### `experimental-useRef-required-initial` false-negative pattern A
#### `useRef-required-initial` false-negative pattern A

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

Expand Down
6 changes: 3 additions & 3 deletions bin/__tests__/types-react-codemod.js
Expand Up @@ -24,9 +24,9 @@ describe("types-react-codemod", () => {
codemod [string] [required] [choices: "context-any", "deprecated-react-child",
"deprecated-react-text", "deprecated-react-type", "deprecated-sfc-element",
"deprecated-sfc", "deprecated-stateless-component",
"deprecated-void-function-component", "experimental-refobject-defaults",
"experimental-useRef-required-initial", "implicit-children", "preset-18",
"preset-19", "scoped-jsx", "useCallback-implicit-any"]
"deprecated-void-function-component", "implicit-children", "preset-18",
"preset-19", "refobject-defaults", "scoped-jsx", "useCallback-implicit-any",
"useRef-required-initial"]
paths [string] [required]
Options:
Expand Down
14 changes: 8 additions & 6 deletions transforms/__tests__/preset-19.js
Expand Up @@ -8,6 +8,7 @@ describe("preset-19", () => {
let deprecatedReactTextTransform;
let deprecatedVoidFunctionComponentTransform;
let refobjectDefaultsTransform;
let scopedJSXTransform;
let useRefRequiredInitialTransform;

function applyTransform(source, options = {}) {
Expand Down Expand Up @@ -35,11 +36,10 @@ describe("preset-19", () => {
deprecatedVoidFunctionComponentTransform = mockTransform(
"../deprecated-void-function-component",
);
refobjectDefaultsTransform = mockTransform(
"../experimental-refobject-defaults",
);
refobjectDefaultsTransform = mockTransform("../refobject-defaults");
scopedJSXTransform = mockTransform("../scoped-jsx");
useRefRequiredInitialTransform = mockTransform(
"../experimental-useRef-required-initial",
"../useRef-required-initial",
);

preset19Transform = require("../preset-19");
Expand All @@ -61,15 +61,17 @@ describe("preset-19", () => {
"deprecated-react-child",
"deprecated-react-text",
"deprecated-void-function-component",
"experimental-refobject-defaults",
"experimental-useRef-required-initial",
"refobject-defaults",
"scoped-jsx",
"useRef-required-initial",
].join(","),
});

expect(deprecatedReactChildTransform).toHaveBeenCalled();
expect(deprecatedReactTextTransform).toHaveBeenCalled();
expect(deprecatedVoidFunctionComponentTransform).toHaveBeenCalled();
expect(refobjectDefaultsTransform).toHaveBeenCalled();
expect(scopedJSXTransform).toHaveBeenCalled();
expect(useRefRequiredInitialTransform).toHaveBeenCalled();
});
});
2 changes: 1 addition & 1 deletion transforms/__tests__/refobject-defaults.js
@@ -1,7 +1,7 @@
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const refobjectDefaultsTransform = require("../experimental-refobject-defaults");
const refobjectDefaultsTransform = require("../refobject-defaults");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
2 changes: 1 addition & 1 deletion transforms/__tests__/useRef-required-initial.js
@@ -1,7 +1,7 @@
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const useRefRequiredInitial = require("../experimental-useRef-required-initial");
const useRefRequiredInitial = require("../useRef-required-initial");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(useRefRequiredInitial, options, {
Expand Down
8 changes: 4 additions & 4 deletions transforms/preset-19.js
@@ -1,9 +1,9 @@
const deprecatedReactChildTransform = require("./deprecated-react-child");
const deprecatedReactTextTransform = require("./deprecated-react-text");
const deprecatedVoidFunctionComponentTransform = require("./deprecated-void-function-component");
const refobjectDefaultsTransform = require("./experimental-refobject-defaults");
const refobjectDefaultsTransform = require("./refobject-defaults");
const scopedJsxTransform = require("./scoped-jsx");
const useRefRequiredInitialTransform = require("./experimental-useRef-required-initial");
const useRefRequiredInitialTransform = require("./useRef-required-initial");

/**
* @type {import('jscodeshift').Transform}
Expand All @@ -25,13 +25,13 @@ const transform = (file, api, options) => {
if (transformNames.has("deprecated-void-function-component")) {
transforms.push(deprecatedVoidFunctionComponentTransform);
}
if (transformNames.has("experimental-refobject-defaults")) {
if (transformNames.has("refobject-defaults")) {
transforms.push(refobjectDefaultsTransform);
}
if (transformNames.has("scoped-jsx")) {
transforms.push(scopedJsxTransform);
}
if (transformNames.has("experimental-useRef-required-initial")) {
if (transformNames.has("useRef-required-initial")) {
transforms.push(useRefRequiredInitialTransform);
}

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 80fe29c

Please sign in to comment.