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

Reader: Use localize() instead of i18n mixin #13759

Merged
merged 8 commits into from
May 10, 2017

Conversation

ockham
Copy link
Contributor

@ockham ockham commented May 8, 2017

Let's continue the tradition of using the Reader as a guinea pig for trying out new codemods 😁

Branch made by running the codemod from #13597, and s/localize\((\S*)\)/localize( $1 )/g.

To test:

  • Verify that the Reader is still properly localized.

@ockham ockham added [Feature] Reader The reader site on Calypso. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 8, 2017
@ockham ockham self-assigned this May 8, 2017
@ockham ockham requested review from blowery, bluefuton and samouri May 8, 2017 16:11
@matticbot
Copy link
Contributor

@matticbot matticbot added the [Size] XL Probably needs to be broken down into multiple smaller issues label May 8, 2017
@ockham ockham mentioned this pull request May 8, 2017
@samouri
Copy link
Contributor

samouri commented May 8, 2017

Any reason the codemod is wrapping the declaration instead of the line with the export (how we usually do it)?

Current:

const a = localize( React.createClass( {} ) );
export default a;

Preferred:

const a = React.createClass({});
export default localize( a );

@gziolo
Copy link
Member

gziolo commented May 8, 2017

I was about to ask about the same :) It might break one of the Babel's transformations which gives the name to the components. Another thing is that React.createClass is something that Eslint no longer loves :)

@samouri
Copy link
Contributor

samouri commented May 8, 2017

Let's continue the tradition of using the Reader as a guinea pig for trying out new codemods 😁

Love it btw 🎉

@ockham
Copy link
Contributor Author

ockham commented May 8, 2017

Any reason the codemod is wrapping the declaration instead of the line with the export (how we usually do it)?

It was way easier to wrap localize directly around createClass (for which there is a readily available util in react-codemod) than to account for different possible cases such as export default, non-default export, variable assignment, etc.

@ockham ockham force-pushed the update/reader-drop-this-translate branch from fbcae70 to ba918ac Compare May 9, 2017 21:58
@ockham
Copy link
Contributor Author

ockham commented May 9, 2017

Any reason the codemod is wrapping the declaration instead of the line with the export (how we usually do it)?

Thanks to @jsnajdr's contribution to #13597, the codemod is now smarter! I re-ran it on client/reader and updated this PR accordingly.

@gziolo
Copy link
Member

gziolo commented May 10, 2017

This makes linter very unhappy. Errors from the first container:


/home/ubuntu/wp-calypso/client/reader/update-notice/index.jsx
  39:2  error  Mixed spaces and tabs                           no-mixed-spaces-and-tabs
  42:1  error  Line 42 exceeds the maximum line length of 140  max-len

/home/ubuntu/wp-calypso/client/reader/following-edit/sort-controls.jsx
  33:2  error  Mixed spaces and tabs  no-mixed-spaces-and-tabs

/home/ubuntu/wp-calypso/client/reader/recommendations/posts/index.jsx
  18:3  error  Unexpected var, use let or const instead  no-var
  22:2  error  Mixed spaces and tabs                     no-mixed-spaces-and-tabs

/home/ubuntu/wp-calypso/client/reader/stream/empty.jsx
  40:2  error  Mixed spaces and tabs  no-mixed-spaces-and-tabs

/home/ubuntu/wp-calypso/client/reader/following-edit/import-button.jsx
  72:2  error  Mixed spaces and tabs  no-mixed-spaces-and-tabs

✖ 7 problems (7 errors, 0 warnings)

There are 3 more container to check, but it could be easily fixed by prettier (see #12260) :)

Expect me to advertise prettier more each time we introduce new codemod :D

@jsnajdr
Copy link
Member

jsnajdr commented May 10, 2017

This makes linter very unhappy. Errors from the first container:

Some eslint --fix processing will be necessary here.

  • when formatting the output, recast doesn't support the space-in-parens rule (or maybe it's just not turned on?)
  • it has a bug when formatting JSX -- inserts spaces before the opening tag despite the useTabs option

@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

I ran ./node_modules/.bin/eslint --fix client/reader/, and it doesn't seem to be able to fix no-mixed-spaces-and-tabs (yet -- I might need to check the Changelog and maybe update to a more recent version).

@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

@gziolo Anyway, it looks like most of these lints aren't even introduced by the codemod but seem to pre-exist, no? (Check the affected lines.) If that's the case, I'd say it's fine to ignore them and consider them an orthogonal issue.

@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

Hmm, on second glance, I might be wrong about that 😳

@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

I ran ./node_modules/.bin/eslint --fix client/reader/, and it doesn't seem to be able to fix no-mixed-spaces-and-tabs (yet -- I might need to check the Changelog and maybe update to a more recent version).

Computer says no: eslint/eslint#6873

@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

Resorted to using Atom to replace with . Which seems to have worked 😄

@gziolo
Copy link
Member

gziolo commented May 10, 2017

IDE is your friend. That works, too :)
I think you can skip other errors, because they were existing before.

I was using --fix with https://github.com/Automattic/delphin which has a different setup. To be honest I don't remember which rules worked :) I know that some of them work. What I remember is, I decided to explicitly provide rule to be fixed.

@@ -3,6 +3,8 @@
*/
import React from 'react';

Copy link
Member

@gziolo gziolo May 10, 2017

Choose a reason for hiding this comment

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

I'm wondering why it adds empty line here and in a couple of other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's benjamn/recast#371

@jsnajdr
Copy link
Member

jsnajdr commented May 10, 2017

I ran ./node_modules/.bin/eslint --fix client/reader/, and it doesn't seem to be able to fix no-mixed-spaces-and-tabs

If you mean the spaces added before an opening JSX element, I isolated the bug in recast and will be coming up with a patch. It won't be a problem for long, hopefully.

@@ -19,7 +20,7 @@ import {
} from 'reader/stats';
import cssSafeUrl from 'lib/css-safe-url';

export default React.createClass( {
export default localize(React.createClass({
Copy link
Member

Choose a reason for hiding this comment

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

Missing spaces inside localize.

@gziolo
Copy link
Member

gziolo commented May 10, 2017

I had two minor comments, otherwise it looks neat. I think it needs to be tested by someone from Reader team and we are good to 🚢

@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

I ran ./node_modules/.bin/eslint --fix client/reader/, and it doesn't seem to be able to fix no-mixed-spaces-and-tabs

If you mean the spaces added before an opening JSX element, I isolated the bug in recast and will be coming up with a patch. It won't be a problem for long, hopefully.

Nice! Wanna add a link to the PR for reference? 😄

@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

I think it needs to be tested by someone from Reader team and we are good to 🚢

@blowery @bluefuton @samouri pls? 😄

@jsnajdr
Copy link
Member

jsnajdr commented May 10, 2017

Nice! Wanna add a link to the PR for reference?

Here it is: benjamn/recast#404

@samouri
Copy link
Contributor

samouri commented May 10, 2017

I'll give this a go 🤞

@bluefuton
Copy link
Contributor

I've just fixed up the last couple of lint errors 👍

@samouri
Copy link
Contributor

samouri commented May 10, 2017

I'm on the rest of the style errors ugh
edit: since when were we erroring for things like createClass? I think we should merge this as-is and deal with these unrelated errors separately...

Copy link
Contributor

@samouri samouri left a comment

Choose a reason for hiding this comment

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

I say 🚢

@samouri samouri added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 10, 2017
@samouri samouri merged commit a347672 into master May 10, 2017
@samouri samouri deleted the update/reader-drop-this-translate branch May 10, 2017 16:26
@ockham
Copy link
Contributor Author

ockham commented May 10, 2017

Thanks for merging @samouri!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Reader The reader site on Calypso. [Size] XL Probably needs to be broken down into multiple smaller issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants