prettier / eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
MIT License
5.47k stars 255 forks source link

clarify conflicting READMEs WRT -plugin vs -config "extends" rule #87

Closed lunelson closed 5 years ago

lunelson commented 5 years ago

In this repo's README it is stated that the "extends" rule should list "prettier", but in the README for eslint-plugin-prettier it states that when using this config the "extends" rule should list "plugin:prettier/recommended". Which one of the following is correct, or do they have different meanings? The READMEs of one or both of these packages should be updated.

eslint-plugin-prettier + eslint-config-prettier

{
  "extends": ["plugin:prettier/recommended"]
}

eslint-config-prettier

{
  "extends": ["prettier"]
}
lydell commented 5 years ago

They have different meanings. Here’s what plugin:prettier/recommended looks like:

https://github.com/prettier/eslint-plugin-prettier/blob/a9a2e4e3c0a243ec73061c10d9c4a5ae0c0e6f68/eslint-plugin-prettier.js#L109-L114

    recommended: {
      extends: ['prettier'],
      plugins: ['prettier'],
      rules: {
        'prettier/prettier': 'error'
      }

Do you have any specific suggestions on how this could be clarified?

See also https://prettier.io/docs/en/next/integrating-with-linters.html#eslint

lunelson commented 5 years ago

Well, after cross-referencing these READMEs multiple times I must say I find the recommended config option is itself the problem. The eslint-plugin-prettier README says to do the following:

{
  "plugins": ["prettier"],
  "rules": {
    "prettier/prettier": "error"
  }
}

...and then says in order to integrate eslint-config-prettier you install it and then ADD the following:

{
  "extends": ["plugin:prettier/recommended"]
}

But that single line actually replaces the previous configurations, because it's equivalent to this:

{
  "extends": ["prettier"],
  "plugins": ["prettier"],
  "rules": {
    "prettier/prettier": "error"
}

...which is stated, but IMO not easily understood because the user is told to ADD the plugin:prettier/recommended line, not to REPLACE the previous config with it.

What would be simpler, more explicit and easier to follow is simply tell the user to install eslint-config-prettier and add the following line to the configuration they've already written:

{
  "extends": ["prettier"]
}

...which has the benefit of also agreeing with the README of the eslint-config-prettier package.

I honestly think you should deprecate plugin:prettier/recommended config. It is well-intended but it obscures more than it helps. Moreover, a plugin exporting a config which just re-adds that same plugin is IMO an anti-pattern. If it added a complex list of obscure dependencies in a specific order it might be worthwhile but here the full explicit config is actually easier to read and understand than the "recommended" convenience option.

lydell commented 5 years ago

Thanks. Feel free to open an issue over at the eslint-plugin-prettier repo.