Skip to content
This repository was archived by the owner on Feb 9, 2023. It is now read-only.

Conversation

@ota-meshi
Copy link
Member

@ota-meshi ota-meshi commented Apr 4, 2020

Which issue, if any, is this issue related to?

Close #12

Is there anything in the PR that needs further explanation?

This PR introduces linter and formatter to the repository.


  • When @stylelint/prettier-config is released, use it.
  • When a new version of eslint-config-stylelint is released, use it.

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Thanks!

.eslintrc.js Outdated
@@ -0,0 +1,13 @@
module.exports = {
Copy link
Member

@jeddy3 jeddy3 Apr 4, 2020

Choose a reason for hiding this comment

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

Let's standardise how we do this across projects, like so:

// package.json
{
  "scripts": {
    "format": "prettier . --write",
    "lint:formatting": "prettier . --check",
    "lint:js": "eslint . --ignore-path .gitignore",
    "lint": "npm-run-all --parallel lint:*",
    "release": "np",
    "test": "jest",
    "watch": "jest --watch"
  },
  "eslintConfig": {
    "extends": [
      "stylelint"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.js": "eslint --cache --fix",
    "*.(js,md,yml}": "prettier --write"
  }
}

Integrating Prettier into ESLints floods our editors with squiggly red lines for unimportant formatting issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for your review!

I made this change.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the linting run-script commands.

Integrating Prettier into ESLint floods our editors with squiggly red lines for unimportant formatting issues.

Can you:

  • replace eslint-config-prettier with a npm run format command
  • move the eslint config into package.json

So that it is consistent with the other stylelint repos.

Like so:

// package.json
{
  "scripts": {
    "format": "prettier . --write",
    "lint:formatting": "prettier . --check",
    "lint:js": "eslint . --ignore-path .gitignore",
    "lint": "npm-run-all --parallel lint:*",
  },
  "eslintConfig": {
    "extends": [
      "stylelint"
    ],
    parserOptions: {
      ecmaVersion: 2019,
    },
     rules: {
	'jest/valid-expect': 'off',
     }
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved the eslint configuration to package.json.

However, eslint-config-prettier is required. This prevents conflict between prettier and eslint. Specifically, it conflicts with "no-mixed-spaces-and-tabs".

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, my bad. I mixed up the prettier plugin with the prettier config.

We should move eslint-config-prettier into eslint-config-stylelint, like we intend to do with the equivalent remark preset in @stylelint/remark-preset, as it's applicable to all stylelint repos.

We can do this in a follow-up pull request once we release a new version of eslint-config-stylelint, though.

@@ -0,0 +1,23 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer we use Prettier without any settings as we offload any decision making to that team (see version Prettier 2 changes) and I don't believe there's an easy way to share a Prettier config across repos, which means we have to keep them in sync manually.

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe there's an easy way to share a Prettier config across repos

Scratch that: https://prettier.io/docs/en/configuration.html#sharing-configurations

If the general consensus is to define our own settings then let's pull them out into @stylelint/prettier-config and roll them out across the org. We can do that in a follow-up pull request, one that probably uses remark-preset-lint-stylelint too.

Copy link
Member

Choose a reason for hiding this comment

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

Pull request pending at stylelint/prettier-config#1

@@ -1,14 +1,18 @@
*.log
*.pid
Copy link
Member

@jeddy3 jeddy3 Apr 4, 2020

Choose a reason for hiding this comment

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

I'll create a follow-up PR to move to a files: [] whitelisting approach.

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Thanks for making changes. I've requested a follow-up one.

.eslintrc.js Outdated
@@ -0,0 +1,13 @@
module.exports = {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the linting run-script commands.

Integrating Prettier into ESLint floods our editors with squiggly red lines for unimportant formatting issues.

Can you:

  • replace eslint-config-prettier with a npm run format command
  • move the eslint config into package.json

So that it is consistent with the other stylelint repos.

Like so:

// package.json
{
  "scripts": {
    "format": "prettier . --write",
    "lint:formatting": "prettier . --check",
    "lint:js": "eslint . --ignore-path .gitignore",
    "lint": "npm-run-all --parallel lint:*",
  },
  "eslintConfig": {
    "extends": [
      "stylelint"
    ],
    parserOptions: {
      ecmaVersion: 2019,
    },
     rules: {
	'jest/valid-expect': 'off',
     }
  }
}

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Looking good. One request and one query.

.prettierrc.js Outdated
endOfLine: 'lf',
printWidth: 100,
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.

We use trailingComma: 'all' in the main repo. Which do we want to standardise on and use here (and in @stylelint/config-prettier)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently released eslint-config-stylelint uses ES6, so trailingComma of function argument cannot be used.
https://github.com/stylelint/eslint-config-stylelint/blob/11.1.0/eslintrc.js#L12

Specify ecmaVersion: 2019 in individual eslintConfig?

Copy link
Member

Choose a reason for hiding this comment

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

Let's release a new version of eslint-config-stylelint with ecmaVersion: 2019.

In the meantime, let's offload the decision about trailing commas to Prettier and use their default (which as of version 2 is es5):

Change default value for trailingComma to es5
There is a possibility that the default value will change to always (meaning even more trailing commas) in a future major version of Prettier as the JavaScript ecosystem further matures.

Please remove trailingComma: 'es5' from this pull request and I'll remove trailingComma: 'all' from @stylelint/prettier-config.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have removed trailingComma from .prettierrc.

]
},
"scripts": {
"lint:formatting": "prettier . --check",
Copy link
Member

@jeddy3 jeddy3 Apr 4, 2020

Choose a reason for hiding this comment

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

We should add a "format": "prettier . --write", command for consistency with the other stylelint repos. Therefore, regardless of the underlying tool (for example, Jest or Mocha), the same main commands work across repositories: format, lint, test, watch, release.

@ota-meshi
Copy link
Member Author

I have made the changes you requested.

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Almost there. One last amend and I think the pull request is ready.

package.json Outdated
"lint:formatting": "prettier . --check",
"lint:js": "eslint .",
"lint": "npm-run-all --parallel lint:*",
"pretest": "npm run lint",
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the pretest lifecycle command and replace with a "lint" task, like so as we only want lint once on the CI. This will be consistent with other repositories.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the 'pretest' script and added lint to CI.

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Thank you!

The CI looks great with one lint run and two test runs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Use prettier to format code

3 participants