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

Add a prettier config #46

Merged
merged 17 commits into from Oct 25, 2017
Merged

Add a prettier config #46

merged 17 commits into from Oct 25, 2017

Conversation

ismail-syed
Copy link
Contributor

@ismail-syed ismail-syed commented Oct 12, 2017

  • Created and exposed a prettier config that can be consumed for JS projects via plugin:shopify/prettier.
  • Formatted this repo with the new config

This PR also adds the following dependencies:

Ran this against core, here's a diff to get an idea of potential changes. Let me know if you see any concerns.


function isRestrictedModule(mod) {
return restricted.indexOf(mod) >= 0;
}

/* eslint-disable prettier/prettier*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

eslint --fix with the prettier/prettier config breaks this. It outputs invalid code. Create a reproducible issue in issue in eslint-plugin-prettier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

Instead of disabling prettier here, you can run eslint --fix, manually correct the syntax error, and the eslint --fix again.

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 the tip.
I'd prefer leaving as is. I've commented a link to the issue for context.

}

/* eslint-disable prettier/prettier*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here, eslint --fix with the prettier/prettier config breaks this. It outputs invalid code. Create a reproducible issue in issue in eslint-plugin-prettier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Space before the last *

@@ -2,5 +2,6 @@ module.exports = {
extends: 'plugin:shopify/esnext',
rules: {
'import/no-extraneous-dependencies': 'off',
'prettier/prettier': 'off',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, we could extend the plugin:shopify/prettier config and run prettier against the /tests code.

Copy link
Member

Choose a reason for hiding this comment

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

I like the alternative better

package.json Outdated
@@ -18,6 +18,8 @@
"rules-status": "eslint-index lib/config/all.js --format table",
"rules-omitted": "eslint-index lib/config/all.js --status omitted",
"lint": "eslint . --max-warnings 0",
"format": "prettier --write --single-quote --no-bracket-spacing --trailing-comma es5 './**/*.js'",
"eslint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we update prettier and/or eslint hopefully, this can continue to list conflicting rules.

@ismail-syed ismail-syed changed the title [WIP] Add a prettier config Add a prettier config Oct 17, 2017
package.json Outdated
@@ -18,6 +18,7 @@
"rules-status": "eslint-index lib/config/all.js --format table",
"rules-omitted": "eslint-index lib/config/all.js --status omitted",
"lint": "eslint . --max-warnings 0",
"prettier-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.eslintrc.js should point to esnext prettier config instead.

@@ -3,9 +3,7 @@ module.exports = {
jquery: true,
},

plugins: [
'shopify',
],
Copy link
Member

Choose a reason for hiding this comment

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

Are these changes the result of running prettier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, it's within the 80 column size .

],

// rules to disable to prefer prettier
'shopify/binary-assignment-parens': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shopify/binary-assignment-parens expects something like this:

const always = (config === 'always');

This will cause prettier to complain:

$ eslint . --max-warnings 0

/Users/ismailsyed/src/github.com/Shopify/eslint-plugin-shopify/lib/rules/class-property-semi.js
  14:20  error  Replace `(config·===·'always')` with `config·===·'always'`  prettier/prettier

Unfortunately, we'll have to turn this rule off in favor of the 'prettier' experience.
No pun intended, lol.

'error',
{
singleQuote: true,
trailingComma: 'es5',
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think we need to change this for the ESNext config — any way of making this dynamic based on other configs passed in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The prettier config will disable the rule(s) regardless of the config passed in.

Extending this prettier config forces you to opt-in to the opinionated prettier experience. If a consumer wants, they can update the prettier/prettier rules in their config.

    'prettier/prettier': [
      'error',
      {
        singleQuote: true,
        trailingComma: '<none|es5|all>',
        bracketSpacing: false,
        jsxBracketSameLine: false,
      },
    ],

}

/* eslint-disable prettier/prettier*/
Copy link
Member

Choose a reason for hiding this comment

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

Space before the last *

@@ -2,5 +2,6 @@ module.exports = {
extends: 'plugin:shopify/esnext',
rules: {
'import/no-extraneous-dependencies': 'off',
'prettier/prettier': '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 like the alternative better

'flowtype',
'shopify',
],
plugins: ['flowtype', 'shopify'],
Copy link
Member

Choose a reason for hiding this comment

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

There's also a config for prettier/flowtype (in addition to one for React) — do we want those?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. That work can be in a future PR. We'll have to manually find out which rules from those configs we'll need to turn off.

@ismail-syed
Copy link
Contributor Author

Comments addressed, ready for another 👀

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.

It's a clever idea to show the effect of Prettier in this PR, but it's making it difficult to sift out what has really changed.

From my first sift through, two things that I'm not comfortable with:

  • Arrays being translated to single lines based on line width
    • This seems at odds with our "trailing comma makes it easier to track the originator of a change" philosophy
  • [{ being rewritten to have the opening brace on a new line

The second thing I'm sure I'll get over. The first seems like it should be up to the developer.

@ismail-syed
Copy link
Contributor Author

ismail-syed commented Oct 23, 2017

I kept all the automated --fix with the prettier changes in this one commit, 5c2baf3. I should have mentioned that in the PR description, sorry.
It might be helpful to view it in the individual commit instead.

@@ -49,6 +51,7 @@
"isparta": "^4.0.0",
"istanbul": "^0.4.5",
"mocha": "^3.4.2",
"prettier": "^1.7.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move to dependencies

Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So consumers don't have to install prettier.

Copy link
Member

Choose a reason for hiding this comment

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

I just worry about it needing to be aligned across repos, technically they would need to install it now in order to run the command alongside the linter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spoke offline with Chris. We're going to add prettier as an optional dependency since prettier is only required when extending the prettier config.

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.

This feels fine to me, I'm OK with the occasional non-ideal formatting.

@ismail-syed ismail-syed merged commit 45504b6 into master Oct 25, 2017
@kaelig kaelig deleted the prettier-v1.7.2 branch January 12, 2018 02:29
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.

None yet

4 participants