eslint-plugin-prettier icon indicating copy to clipboard operation
eslint-plugin-prettier copied to clipboard

Add `eslint-config-prettier` to `dependencies`

Open zaicevas opened this issue 4 years ago • 8 comments

Currently, eslint-config-prettier is a dev and peer dependency.

This causes an error when trying to extend plugin:prettier/recommended in another shareable ESLint config. Linting in VSCode results in an error

image

As described in https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files:

Relative paths and shareable config names in an extends property are resolved from the location of the config file where they appear.

Since eslint-plugin-prettier uses eslint-config-prettier, I think it should work (I haven't tried it) if eslint-plugin-prettier would move eslint-config-prettier to dependencies, which would eliminate the need for a peer dependency.

What do you think?

zaicevas avatar Jan 14 '22 14:01 zaicevas

I think eslint-config-prettier should not be marked as an optional dependency,the following should be removed from package json:

  "peerDependenciesMeta": {
    "eslint-config-prettier": {
      "optional": true
    }
  },

marcinvalas avatar Jan 20 '22 12:01 marcinvalas

It is perfectly possible to use this package without using behaviour that depends upon eslint-config-prettier, thus it is an optional dependency. Adding a direct dependency can also potentially lead to duplication of eslint-config-prettier in your package.json which can then cause further problems.

BPScott avatar Jan 20 '22 18:01 BPScott

the problem here, with optional eslint-config-prettier dependency, is it is not possible to build a self-sufficient eslint preset module. In the end project, you still need to install eslint-config-prettier next to eslint preset module.

marcinvalas avatar Jan 24 '22 21:01 marcinvalas

Yes that seems reasonable. You can explicitly control the version eslint-config-prettier you desire, which would be harder if it was a transitive dependency of eslint-plugin-prettier

BPScott avatar Jan 24 '22 22:01 BPScott

please look, eslint-plugin-prettier is not even using eslint-config-prettier, I done quick search: https://github.com/prettier/eslint-plugin-prettier/search?q=eslint-config-prettier so why eslint-config-prettier is a dependency of eslint-plugin-prettier? It can be easily removed from its package.josn, then I am still able to control the version of eslint-config-prettier and also it solves the problem with a self-sufficient eslint preset

marcinvalas avatar Jan 24 '22 23:01 marcinvalas

This plugin exposes a recommended config that extends from eslint-config-prettier.

You can choose not to use the config - in which case the dependency eslint-config-prettier is not required. Or you can choose to use that config - in which case the dependency eslint-config-prettier is required.

Thus it is an optional dependency, depending on that choice the user makes.

BPScott avatar Jan 25 '22 00:01 BPScott

So how can I prepare eslint preset package which uses prettier (with some custom config too) and in end project install only "one dependency"?

e.g., I want to have a my-app which depends only on eslint and my-eslint-preset

{
    "name": "my-app",
    "devDependency": {
       "eslint": "",
       "my-eslint-preset": ""
    }
}

where my-eslint-preset is

{
  "name": "  my-eslint-preset",
   "dependency": {
       "eslint-config-prettier": "",
       "eslint-plugin-prettier": "",
       "some-another-eslint-plugin": ""
       // .....
    },
    "devDependencies": {
        "eslint": "",
    }
}

?


currently, in app my-app" I need to install eslint-config-prettier too:

{
    "name": "my-app",
    "devDependency": {
       "eslint": "",
       "my-eslint-preset": ""
       "eslint-config-prettier": "",
    }
}

marcinvalas avatar Jan 25 '22 07:01 marcinvalas

currently, in app my-app" I need to install eslint-config-prettier too:

You shouldn't need to do this. The dependency on my-eslint-preset is enough to trigger pulling in eslint-config-prettier.

@shopify/eslint-plugin follows the pattern you describe - depending on both eslint-config-prettier and eslint-plugin-prettier, and I have several repositories that depend up only @shopify/eslint-plugin without issue.

BPScott avatar Jan 25 '22 23:01 BPScott