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

Lint: Disable errors for formatting handled by prettier #24635

Merged
merged 8 commits into from
May 14, 2018

Conversation

blowery
Copy link
Contributor

@blowery blowery commented May 2, 2018

Since we now use prettier to format all of our code, we can turn eslint formatting errors covered by prettier (max-len, indent...). Prettier provides a config to do just that in eslint-format-prettier.

The only real problem we have now is ternary expressions, so we could just ignore those nodes instead.

See #24504, #24571

@matticbot
Copy link
Contributor

@blowery blowery added Framework Build [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 2, 2018
@blowery blowery force-pushed the try/eslint/turn-off-indent branch from 098f1cb to 0da0540 Compare May 2, 2018 18:51
@blowery blowery requested review from ockham, gziolo and a team May 2, 2018 19:44
// REST API objects include underscores
camelcase: 0,

// TODO: why did we turn this off?
Copy link
Member

@gziolo gziolo May 4, 2018

Choose a reason for hiding this comment

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

I think it errors because there are still chai matchers which aren't compatible with Jest syntax. I bet the same story as with mocha globals.

parser: 'babel-eslint',
env: {
browser: true,
'jest/globals': true,
// mocha is only still on because we have not finished porting all of our tests to jest's syntax
mocha: true,
Copy link
Member

Choose a reason for hiding this comment

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

You can try to turn it off as we most likely migrated all globals to Jest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, different PR for that though.

@blowery
Copy link
Contributor Author

blowery commented May 10, 2018

ok, now we really really use prettier for everything

#24752

thanks @sirreal!

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

Excited to remove an annoyance with this 🙂

Added a comment about max-len. If our goal here is "prettier handles that, be silent eslint" PR, then I'd like to remove max-len as well.

Commented a few of the confusing parts of the diff so it's clear what rules aren't changed but have been formatted.

.eslintrc.js Outdated
'jsx-a11y/anchor-has-content': 0,

// error if any given line is over 140 characters long.
// Ideally this would be even lower(120, 80?), but that's a big step.
'max-len': [ 2, { code: 140 } ],
Copy link
Member

Choose a reason for hiding this comment

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

Shall we disable this as well? Prettier's functionality is based on breaking long lines.

A quick search will show lots of disabling for SVG paths or strings that aren't broken.

Copy link
Member

Choose a reason for hiding this comment

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

Would remove 98 lint errors according to #24504 (comment) and allow for removal of ~69 {en,dis}able comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good to me. I'll rename this PR.

} ],

// Allows Chai `expect` expressions. Now that we're on jest, hopefully we can remove this one.
'no-unused-expressions': 0,
Copy link
Member

Choose a reason for hiding this comment

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

No change, layout and comment.

{
rootFiles: [ 'index.js', 'index.jsx', 'main.js', 'main.jsx' ],
},
],
Copy link
Member

Choose a reason for hiding this comment

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

No change, layout and comment.

.eslintrc.js Outdated
}

// turn off indenting rules since we let prettier handle it
indent: 0,
Copy link
Member

Choose a reason for hiding this comment

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

New rule disabling eslint indent 🎉

.eslintrc.js Outdated
'jsx-a11y/anchor-has-content': 0, // i18n-calypso translate triggers false failures

// i18n-calypso translate triggers false failures
'jsx-a11y/anchor-has-content': 0,
Copy link
Member

Choose a reason for hiding this comment

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

No change, layout.

@sirreal
Copy link
Member

sirreal commented May 11, 2018

I've pushed a commit that removes the now-redundant indent disable/enable comments. Feels so good!

@sirreal sirreal force-pushed the try/eslint/turn-off-indent branch from 8a4baa6 to 0870b52 Compare May 11, 2018 07:20
@sirreal
Copy link
Member

sirreal commented May 11, 2018

I've rebased. There was a new indent ignore that had been added, which is now removed 🙄

@blowery blowery changed the title Lint: Turn off indent errors Lint: Disable errors for formatting handled by prettier May 11, 2018
@blowery
Copy link
Contributor Author

blowery commented May 11, 2018

@sirreal taking a slightly different approach here. I'm going to pull in and use https://github.com/prettier/eslint-config-prettier

@blowery
Copy link
Contributor Author

blowery commented May 11, 2018

Adding the prettier eslint config has the following effect:
npx eslint --ext js,jsx client

--- before	2018-05-11 10:28:38.000000000 -0400
+++ after	2018-05-11 10:28:50.000000000 -0400
@@ -1,11 +1,9 @@
-indent: 1790
 wpcalypso/jsx-classname-namespace: 844
 prefer-const: 647
 react/no-string-refs: 249
 valid-jsdoc: 247
 jsx-a11y/click-events-have-key-events: 106
 jsx-a11y/no-static-element-interactions: 98
-max-len: 98
 jsx-a11y/anchor-is-valid: 69
 jsx-a11y/alt-text: 62
 jsx-a11y/label-has-for: 41
@@ -38,14 +36,12 @@
 react/no-did-mount-set-state: 3
 react/no-is-mounted: 3
 jsx-a11y/media-has-caption: 2
-no-multi-spaces: 2
 no-var: 2
 eqeqeq: 1
 jsx-a11y/html-has-lang: 1
 jsx-a11y/role-has-required-aria-props: 1
 no-nested-ternary: 1
 no-use-before-define: 1
-operator-linebreak: 1
 wpcalypso/i18n-no-variables: 1

-total: 4585
+total: 2694

@samouri
Copy link
Contributor

samouri commented May 11, 2018

Disable errors for formatting handled by prettier

This PR is doing a lot more than that right?

@@ -21,21 +21,20 @@ class StatsFirstView extends React.PureComponent {
<div>
{ this.renderIcon() }
<h1>{ this.props.translate( 'See How Your Site Is Performing' ) }</h1>
{ /* eslint-disable max-len */ }
{ }
Copy link
Contributor

Choose a reason for hiding this comment

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

you can delete this { }

@@ -163,7 +163,7 @@ class DeleteSite extends Component {
<ActionPanel>
<ActionPanelBody>
<ActionPanelFigure>
{ /* eslint-disable max-len */ }
{ }
Copy link
Contributor

Choose a reason for hiding this comment

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

this one too

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.

Two small changes, but after fixing those feel free to 🚢

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

I cleaned up the empty braces @samouri spotted.

Looked through code, seems correct.
Smoke tested, didn't spot any errors.

Let's 🚢 !

@@ -186,7 +186,7 @@ export const regexp = memoize( function( tag ) {
return new RegExp(
'\\[(\\[?)(' +
tag +
')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', // eslint-disable-line max-len
')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)',
Copy link
Member

Choose a reason for hiding this comment

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

😮 🙈

const REGEXP_ATTR_STRING = /(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/g; // eslint-disable-line max-len
const REGEXP_SHORTCODE = /\[(\[?)([^\[\]\/\s\u00a0\u200b]+)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/; // eslint-disable-line max-len
const REGEXP_ATTR_STRING = /(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/g;
const REGEXP_SHORTCODE = /\[(\[?)([^\[\]\/\s\u00a0\u200b]+)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/;
Copy link
Member

Choose a reason for hiding this comment

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

😵

@blowery blowery added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 14, 2018
@blowery blowery merged commit cddb367 into master May 14, 2018
@blowery blowery deleted the try/eslint/turn-off-indent branch May 14, 2018 13:52
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants