-
Notifications
You must be signed in to change notification settings - Fork 18
Upgrade Prettier to ^1.9.2 (arrowParens: always) 🎉 & update dependencies #63
Conversation
310405d
to
3234e92
Compare
I'm not sure how to write tests, or if it's necessary at all to write any for the |
package.json
Outdated
"eslint-plugin-flowtype": "^2.40.1", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-lodash": "^2.5.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like dependencies are just being bumped without updating our configs to reflect new rules / options. Are we okay with just using whatever the defaults are?
e.g.,
eslint-plugin-lodash@2.5.0
introduces import-scope
.
eslint-plugin-import@2.8.0
introduces exports-last
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for asking!
eslint-plugin-lodash@2.5.0 introduces import-scope.
Looks like we already had a rule for that, maybe the yarn version was already set to 2.5.0.
// Prefer a specific import scope (e.g. lodash/map vs lodash)
'lodash/import-scope': ['error', 'method'],
As for exports-last
, it's disabled by default. Should I explicitly set it to 'off'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that we explicitly set a value for all options. @lemonmade, that's correct?
Most likely, there are many more new rules + new options. I'd rather someone trawl through changelogs and produce curated PRs, instead of a shotgun update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we try to provide explicit settings for all rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely, there are many more new rules + new options. I'd rather someone trawl through changelogs and produce curated PRs, instead of a shotgun update.
I checked yarn.lock and it turns out we were already using the latest version of those 2 plugins. I guess the trick is to control which version is in the yarn.lock and make sure to document those upgrades too.
Let me go through the diffs and upgrade this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the body of the PR with a list of all new rules and a TODO. I'll add explicit settings for all those rules as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GoodForOneFare @lemonmade I've just updated the PR with new rules explicitly set to off
when applicable. Can you please have another look?
// enforces the any type is not used. (no-any from TSLint) | ||
'typescript/no-explicit-any': 'off', | ||
// disallow generic Array constructors | ||
'typescript/no-array-constructor': 'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is set to 'error' (and not turned off), to replicate this ESLint rule:
eslint-plugin-shopify/lib/config/rules/stylistic-issues.js
Lines 85 to 86 in 9c33d00
// Disallow use of the Array constructor | |
'no-array-constructor': 'error', |
ESLint original rule: https://eslint.org/docs/rules/no-array-constructor
eslint-plugin-typescript: https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/no-array-constructor.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add this to the CHANGELOG, please.
e14d003
to
422b9d3
Compare
I think I'm done with this PR - can you please give it another 👀? Merci! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, it would be better to split this into two PRs so that the Prettier upgrade can ship today.
Are most of the rules turned off because they're not useful, or to expedite the PR?
At minimum, the PR is still missing:
- lines-between-class-members
- multiline-comment-style
- flowtype/no-mutable-array
- flowtype/no-unused-expressions
- promise/no-return-in-finally
}, | ||
"peerDependencies": { | ||
"eslint": "<5 >=4.7.1" | ||
}, | ||
"optionalDependencies": { | ||
"prettier": "<2.0 >= 1.7.2" | ||
"prettier": "<2.0 >= 1.9.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike that this installs prettier
even when consuming projects don't use it. I'd like to move it to peerDependencies
.
Make sense, @ismail-syed and @lemonmade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but is this in the scope of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought optional dependencies was the right thing — doesn't peer
require the installation, even if unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike that this installs prettier even when consuming projects don't use it
I agree. Optional dependencies aren't what we expected them to be.
As per yarn docs
Optional dependencies are just that: optional. If they fail to install, Yarn will still say the install process was successful.
prettier will still be installed; in the chance that it fails, yarn install
will still succeed.
I suggest we change it to a peer dependency like we do with eslint
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a repo that confirms the optional/peer behaviour: https://github.com/GoodForOneFare/dependency-install-types
- Optionals are installed for all consumers
- Peers generate warnings during
yarn install
, and are not installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like something that should be discussed outside of this PR, unless I’m missing something?
You raise good points, and I'm sorta concerned by the overhead of maintaining this growing number of rules 🧐 As far as this PR is concerned, the missing rules are unrelated (they can be added separately, no?). Should we really hold off merging it? |
If rules were added as Since the last dependency bump PR serves as a good reference for the next PR, I'd rather produce a well-curated example for everyone. That said, this isn't a formally documented rule, so ¯\(ツ)/¯ I'll defer to the original assigned reviewers, and bow out of this discussion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left what I think are the right configuration options for rules we actually want to turn on. I am fine with changing those in a follow-up PR and to ship this as-is (although in future, I'd recommend only upgrading the things you actually need to avoid having this kind of creep in the first place)
lib/config/rules/react.js
Outdated
@@ -3,10 +3,14 @@ module.exports = { | |||
|
|||
// Enforces consistent naming for boolean props | |||
'react/boolean-prop-naming': 'off', | |||
// Prevent usage of button elements without an explicit type attribute | |||
'react/button-has-type': 'off', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/config/rules/react.js
Outdated
@@ -15,6 +19,8 @@ module.exports = { | |||
'react/forbid-foreign-prop-types': 'error', | |||
// Forbid certain propTypes | |||
'react/forbid-prop-types': ['error', {forbid: ['any', 'array']}], | |||
// Prevent using this.state within a this.setState | |||
'react/no-access-state-in-setstate': 'off', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/config/rules/react.js
Outdated
@@ -90,6 +96,8 @@ module.exports = { | |||
'react/jsx-closing-bracket-location': ['error', {location: 'tag-aligned'}], | |||
// Validate closing tag location in JSX | |||
'react/jsx-closing-tag-location': 'error', | |||
// Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children | |||
'react/jsx-curly-brace-presence': 'off', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
['error', 'never']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
```diff | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"trailingComma": "es5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our config uses trailingComma: 'all'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, is that something we should also standardize? Looks like not all codebases use it like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure it is consistent, our listing rules have always enforced trailing commas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which code bases don't use it? They should be, unless they have a good reason not too.
In the case of eslint-plugin-shopify
, the repo itself uses es5 so we don't break consumers who may be on older versions of node. (eg. u2). We could add a build step in this repo to solve that, but don't think it's worth the effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Just a couple comments.
-
Can we append
& update dependencies
to the title of the PR. When this gets merged it'll be easier to read through the commit history and understand the changes. -
Can we add the newly introduced rules to the changelog as well - example
Did we do a beta test with this on any repos? |
👍
👍
I don't think we have. What codebase would be a good candidate for a test? |
2ca2d5f
to
8353b87
Compare
I usually do However, it might be nice to spread out the testing codebases. Anything blocking |
Thanks! Can you do On |
5ade785
to
8353b87
Compare
Updated dependencies to their latest versions
Updated prettier to 1.9.2, introducing a change in function parens style (set to
arrowParens: 'always'
):Your project config files (
package.json
,.prettierrc
,.eslintrc
…)may need to be updated like so:
"singleQuote": true, "bracketSpacing": false, "trailingComma": "es5", + "arrowParens": "always"
Added a
prettier
script:yarn prettier
now prettifies source filesPrettified source files using the new config
Notable upgrades
v2.6.0...v2.9.0
rule).
rule).
v4.2.2...v4.4.0
v2.39.1...v2.41.0
v6.0.2...v6.0.3
v7.4.0...v7.5.1
jsx-one-expression-per-line
destructuring-assignment
no-access-state-in-setstate
button-has-type
jsx-curly-brace-presence
rule ([#1310][] @jackyho112)v2.3.1...v2.4.0
v1.2.2...v1.3.0
v0.7.0...v0.8.1
typescript/member-naming
— Enforces naming conventions for class members by visibility.typescript/no-array-constructor
— Disallow genericArray
constructorsv9.0.0...v11.0.0
Todo
eslint-plugin-import@2.8.0
exports-last
.