Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Upgrade Prettier to ^1.9.2 (arrowParens: always) 🎉 & update dependencies #63

Merged
merged 17 commits into from
Jan 12, 2018

Conversation

kaelig
Copy link
Contributor

@kaelig kaelig commented Jan 3, 2018

⚠️this is likely to be a breaking change

  • Updated dependencies to their latest versions

  • Updated prettier to 1.9.2, introducing a change in function parens style (set to arrowParens: 'always'):

    // Before
    const foo = myArray.map(foo => {});
    
    // After
    const foo = myArray.map((foo) => {});

    ⚠️ Upgrade path

    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 files

  • Prettified source files using the new config


Notable upgrades


Todo

  • Document all notable rule changes
  • Add an explicit 'off' setting for all new rules
  • Add a setting for a rule we missed in a previous upgrade: eslint-plugin-import@2.8.0 exports-last.

@kaelig
Copy link
Contributor Author

kaelig commented Jan 3, 2018

I'm not sure how to write tests, or if it's necessary at all to write any for the arrowParens: 'always' case. @ismail-syed thoughts?

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",
Copy link
Member

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.

Copy link
Contributor Author

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'?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

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'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.

Copy link
Contributor Author

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',
Copy link
Contributor Author

@kaelig kaelig Jan 5, 2018

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:

// 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

Copy link
Contributor

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.

@kaelig
Copy link
Contributor Author

kaelig commented Jan 8, 2018

I think I'm done with this PR - can you please give it another 👀? Merci!

Copy link
Member

@GoodForOneFare GoodForOneFare left a 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"
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Contributor Author

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?

@kaelig
Copy link
Contributor Author

kaelig commented Jan 9, 2018

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?

@GoodForOneFare
Copy link
Member

If rules were added as off to expedite this PR, they should be removed, or at least flagged with TODO.

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.

Copy link
Member

@lemonmade lemonmade left a 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)

@@ -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',
Copy link
Member

Choose a reason for hiding this comment

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

error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -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',
Copy link
Member

Choose a reason for hiding this comment

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

error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -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',
Copy link
Member

Choose a reason for hiding this comment

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

['error', 'never']

Copy link
Contributor Author

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",
Copy link
Contributor

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'

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

@ismail-syed ismail-syed Jan 12, 2018

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.

Copy link
Contributor

@ismail-syed ismail-syed left a 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

@ismail-syed
Copy link
Contributor

Did we do a beta test with this on any repos?

@kaelig kaelig changed the title Upgrade Prettier to ^1.9.2 (arrowParens: always) 🎉 Upgrade Prettier to ^1.9.2 (arrowParens: always) 🎉 & update dependencies Jan 12, 2018
@kaelig
Copy link
Contributor Author

kaelig commented Jan 12, 2018

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

👍

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?

@ismail-syed
Copy link
Contributor

I don't think we have. What codebase would be a good candidate for a test?

I usually do web and sewing-kit. Sometimes admin to verify if there's no major 💥

However, it might be nice to spread out the testing codebases. Anything blocking polaris-react or polaris-styleguide from being candidates.

@kaelig
Copy link
Contributor Author

kaelig commented Jan 12, 2018

Thanks! Can you do web and sewing-kit? I'll do polaris-react.

On polaris-styleguide we are so many versions of sewing-kit behind that it will definitely 💥

@kaelig kaelig changed the base branch from master to beta January 12, 2018 02:34
@kaelig kaelig merged commit 82a072f into beta Jan 12, 2018
@kaelig kaelig deleted the prettier-upgrade branch January 12, 2018 02:35
@kaelig kaelig mentioned this pull request Mar 27, 2020
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants