Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom createReactClass function name #177

Merged
merged 6 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ You would use:
classNameMatchers: ["BaseComponent"]
```

### `createReactClassName`

Use this option to set a custom name for the import of the `create-react-class` package that is different than `createReactClass`.

Given this example:

```js
import createClass from 'create-react-class';
```

You would use:

```js
createReactClassName: 'createClass'
```

## Is it safe?

If you are using the `propTypes` in a conventional way,
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export default function(api) {
removeImport: state.opts.removeImport || false,
libraries: (state.opts.additionalLibraries || []).concat('prop-types'),
classNameMatchers,
createReactClassName: state.opts.createReactClassName || 'createReactClass',
}

if (state.opts.plugins) {
Expand Down Expand Up @@ -222,7 +223,7 @@ export default function(api) {
}

return (
currentNode.get('callee').node.name === 'createReactClass' ||
currentNode.get('callee').node.name === globalOptions.createReactClassName ||
currentNode.get('callee').node.property.name === 'createClass'
)
})
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/react-create-class-custom-name/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var createSomethingReallySpecial = require('create-react-class');
var PropTypes = require('prop-types');

createSomethingReallySpecial({
propTypes: {
foo: PropTypes.string,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var createSomethingReallySpecial = require('create-react-class');

createSomethingReallySpecial({});
3 changes: 3 additions & 0 deletions test/fixtures/react-create-class-custom-name/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"createReactClassName": "createSomethingReallySpecial"
}