Skip to content

Commit ebe9dcc

Browse files
committed
Tweak option naming
1 parent bb676bd commit ebe9dcc

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ APIs.
66

77
### Usage
88
`npx react-codemod <transform> <path> [...options]`
9-
* `transform` - name of transform, see available transforms below.
9+
* `transform` - name of transform, see available transforms below.
1010
* `path` - files or directory to transform
1111
* use the `--dry` option for a dry-run and use `--print` to print the output for comparison
1212

13-
This will start an interactive wizard, and then run the specified transform.
13+
This will start an interactive wizard, and then run the specified transform.
1414

1515
### Included Transforms
1616

@@ -55,10 +55,10 @@ npx react-codemod manual-bind-to-arrow <path>
5555
Converts ES6 classes that only have a render method, only have safe properties
5656
(statics and props), and do not have refs to Functional Components.
5757

58-
The wizard will ask for 2 options -
58+
The wizard will ask for 2 options -
5959

60-
* **Use arrow functions?**: converts to arrow function. Converts to `function` by default.
61-
* **Destructure props?**: will destructure props in the argument where it is safe to do so.
60+
* **Use arrow functions?**: converts to arrow function. Converts to `function` by default.
61+
* **Destructure props?**: will destructure props in the argument where it is safe to do so.
6262

6363
```sh
6464
npx react-codemod pure-component <path>
@@ -118,7 +118,7 @@ npx react-codemod react-to-react-dom <path>
118118

119119
#### `React-DOM-to-react-dom-factories`
120120

121-
Converts calls like `React.DOM.div(...)` to `React.createElement('div', ...)`.
121+
Converts calls like `React.DOM.div(...)` to `React.createElement('div', ...)`.
122122

123123
```sh
124124
npx react-codemod React-DOM-to-react-dom-factories <path>
@@ -145,11 +145,11 @@ npx react-codemod sort-comp <path>
145145

146146
#### `update-react-imports`
147147

148-
[As of Babel 7.9.0](https://babeljs.io/blog/2020/03/16/7.9.0#a-new-jsx-transform-11154-https-githubcom-babel-babel-pull-11154), when using `runtime: automatic` in `@babel/preset-react` or `@babel/plugin-transform-react-jsx`, you will not need to explicitly import React for compiling jsx. This codemod removes the redundant import statements. It also converts (`import React from 'react'`) to named imports (`import * as React from 'react'`).
148+
[As of Babel 7.9.0](https://babeljs.io/blog/2020/03/16/7.9.0#a-new-jsx-transform-11154-https-githubcom-babel-babel-pull-11154), when using `runtime: automatic` in `@babel/preset-react` or `@babel/plugin-transform-react-jsx`, you will not need to explicitly import React for compiling jsx. This codemod removes the redundant import statements. It also converts default imports (`import React from 'react'`) to named imports (e.g. `import { useState } from 'react'`).
149149

150-
The wizard will ask for 1 option -
150+
The wizard will ask for 1 option -
151151

152-
* **Destructure named imports?**: Destructures named imports (import * as React from 'react') as well as default imports. Does not do this by default.
152+
* **Destructure namespace imports as well?**: If chosen, *namespace* imports like `import * as React` will *also* be converted. By default, it's false, so only default imports (`import React`) are converted.
153153

154154
```sh
155155
npx react-codemod update-react-imports <path>
@@ -207,7 +207,7 @@ To pass more options directly to jscodeshift, use `--jscodeshift="..."`. For exa
207207
npx react-codemod --jscodeshift="--run-in-band --verbose=2"
208208
```
209209

210-
See all available options [here](https://github.com/facebook/jscodeshift#usage-cli).
210+
See all available options [here](https://github.com/facebook/jscodeshift#usage-cli).
211211

212212
### Recast Options
213213

@@ -220,7 +220,7 @@ npx react-codemod <transform> <path> --jscodeshift="--printOptions='{\"quote\":\
220220

221221
#### `explicit-require=false`
222222

223-
If you're not explicitly importing React in your files (eg: if you're loading React with a script tag), you should add `--explicit-require=false`.
223+
If you're not explicitly importing React in your files (eg: if you're loading React with a script tag), you should add `--explicit-require=false`.
224224

225225
### Support and Contributing
226226

bin/cli.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2015-present, Facebook, Inc.
33
*
44
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
5+
* LICENSE file in the root directory of this source tree.
66
*
77
*/
88

@@ -72,7 +72,7 @@ function runTransform({ files, flags, parser, transformer, answers }) {
7272
args.push('--ignore-pattern=**/node_modules/**');
7373

7474
args.push('--parser', parser);
75-
75+
7676
if (parser === 'tsx') {
7777
args.push('--extensions=tsx,ts,jsx,js');
7878
} else {
@@ -100,8 +100,8 @@ function runTransform({ files, flags, parser, transformer, answers }) {
100100
}
101101

102102
if (transformer === 'update-react-imports') {
103-
if (answers.destructureNamedImports) {
104-
args.push('--destructureNamedImports=true');
103+
if (answers.destructureNamespaceImports) {
104+
args.push('--destructureNamespaceImports=true');
105105
}
106106
}
107107

@@ -226,7 +226,7 @@ function run() {
226226
Usage
227227
$ npx react-codemod <transform> <path> <...options>
228228
229-
transform One of the choices from https://github.com/reactjs/react-codemod
229+
transform One of the choices from https://github.com/reactjs/react-codemod
230230
path Files or directory to transform. Can be a glob like src/**.test.js
231231
232232
Options
@@ -371,14 +371,14 @@ function run() {
371371
},
372372
{
373373
type: 'confirm',
374-
name: 'destructureNamedImports',
374+
name: 'destructureNamespaceImports',
375375
when: answers => {
376376
return (
377377
cli.input[0] === 'update-react-imports' ||
378378
answers.transformer === 'update-react-imports'
379379
);
380380
},
381-
message: 'Destructure named imports?',
381+
message: 'Destructure namespace imports (import *) too?',
382382
default: false
383383
}
384384
])

transforms/__tests__/update-react-imports-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ destructureNamedImportTests.forEach((test) => {
8888
defineTest(
8989
__dirname,
9090
'update-react-imports',
91-
{destructureNamedImports: true},
91+
{destructureNamespaceImports: true},
9292
`update-react-imports/${test}`
9393
);
9494
});

transforms/update-react-imports.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(file, api, options) {
1010
const j = api.jscodeshift;
1111
const printOptions = options.printOptions || {};
1212
const root = j(file.source);
13-
const destructureNamedImports = options.destructureNamedImports;
13+
const destructureNamespaceImports = options.destructureNamespaceImports;
1414

1515
// https://github.com/facebook/jscodeshift/blob/master/recipes/retain-first-comment.md
1616
function getFirstNode() {
@@ -98,7 +98,7 @@ module.exports = function(file, api, options) {
9898
const reactIdentifiers = {};
9999
const reactTypeIdentifiers = {};
100100
let canDestructureReactVariable = false;
101-
if (isReactImportUsed && (isDefaultImport || destructureNamedImports)) {
101+
if (isReactImportUsed && (isDefaultImport || destructureNamespaceImports)) {
102102
// Checks to see if the react variable is used itself (rather than used to access its properties)
103103
canDestructureReactVariable =
104104
root

0 commit comments

Comments
 (0)