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 npm-react-codemod #3506

Merged
merged 6 commits into from
Mar 25, 2015
Merged

Add npm-react-codemod #3506

merged 6 commits into from
Mar 25, 2015

Conversation

cpojer
Copy link
Contributor

@cpojer cpojer commented Mar 25, 2015

This adds react-codemod with the following codemods:

  • getDOMNode to React.findDOMNode
  • PureRenderMixin to shouldComponentUpdate using shallowCompare
  • React.createClass to ES6 classes.

See the README for a detailed explanation of how the codemods work.

The codemods are based on jscodeshift and the project structure is based on js-codemod.

The tests can be run using npm test. Publishing this to npm should work as I have fiddled around with js-codemod enough.

@zpao can we pull in #3355 for React 0.13.2? I thought it was going into 0.13.1 but I guess it didn't :)

Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
through the `printOptions` command line argument

* `react-codemod use-strict <file> --printOptions='{"quote":"double"}'`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use-strict doesn't exist, perhaps use a real example

@zpao
Copy link
Member

zpao commented Mar 25, 2015

Lots of lint to fix :) You might need a custom .eslintrc in your folder. grunt lint is a bit noisy for warnings. You can also run npm run lint npm-react-codemod (which will only run for src/ and your folder).

var reactTools = require('react-tools');

function process(source) {
return reactTools.transform(source, {harmony: true, stripTypes: true});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 space indent? you monster.

TRANSFORM=$1
shift

$DIR/node_modules/.bin/jscodeshift -t $DIR/build/$TRANSFORM.js $@
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this isn't going to work on Windows. I thought we were going to make this a js script that used node to shell out to jscodeshift?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh, that's no fun. Let me see what I can do.

@zpao
Copy link
Member

zpao commented Mar 25, 2015

fun fact, I can't actually use react-codemod in node 0.10 because it doesn't support const and those aren't transformed away.

@cpojer
Copy link
Contributor Author

cpojer commented Mar 25, 2015

I'm on v0.10.37 and it works fine for me? Should I move back to var's?

@cpojer
Copy link
Contributor Author

cpojer commented Mar 25, 2015

Changed to use babel.

@zpao
Copy link
Member

zpao commented Mar 25, 2015

ok, should be good to go

cpojer added a commit that referenced this pull request Mar 25, 2015
@cpojer cpojer merged commit 86836c8 into facebook:master Mar 25, 2015
@cpojer cpojer deleted the react-codemod branch March 25, 2015 23:37
@sophiebits
Copy link
Collaborator

jest now fails because it picks up your transform tests but jscodeshift isn't in the root package.json.

@cpojer
Copy link
Contributor Author

cpojer commented Mar 25, 2015

oh damn, why didn't travis not catch that? :(

@zpao
Copy link
Member

zpao commented Mar 25, 2015

oh hmm, I thought i actually checked that locally…

why didn't travis not catch that?

Because we're having issues with travis and jest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants