Eslint should be specified in project dependencies, not devDependencies

Or I do not understand dependencies vs. devDependencies in node is 100%, or eslint is simply wrong here (unable to parse this correctly):

  3:1 error 'chai' should be listed in the project dependencies, not devDependencies import/no-extraneous-dependencies 4:1 error 'chai-enzyme' should be listed in the project dependencies, not devDependencies import/no-extraneous-dependencies 5:1 error 'enzyme' should be listed in the project dependencies, not devDependencies import/no-extraneous-dependencies 7:1 error 'sinon' should be listed in the project dependencies, not devDependencies import/no-extraneous-dependencies 9:1 error 'redux-mock-store' should be listed in the project dependencies, not devDependencies import/no-extraneous-dependencies 

These are test dependencies, so why do they say they should be listed in dependencies ?

Additional note: we use Travis as our CI, so I don’t know if this really matters.

+25
source share
3 answers

Solved this by adding this to my .eslintrc :

"import/no-extraneous-dependencies": ["error", {"devDependencies": true}]

[no-extraneous-dependencies] Add exceptions? # 422

Based on this user response :

you can set the devDependencies: true option in .eslintrc in your test folder:

rules: import / no-extraneous-dependencies: [error, {devDependencies: true}] You will then receive reports of any packages referenced that are not included dependencies or devDependencies. Then you get the quality factor of the rule, without noise from disabled comments .

I think this might work for you? This is how I would use the rule in your case, since your test code is divided into a test directory.

Also this post was useful to confirm that I was not crazy, not to want some of them in my list of dependencies : Sharable ESLint Config

+41
source

If you want to allow the import of devDependencies in test files, you can use array of globs , since the documentation on the status is no-extraneous-dependencies :

When using an array of globes, the parameter will be set to true (no errors are reported) if the name of the marked file matches one globe in the array, and false otherwise.

The following setting will disable fluff only for test files.

 "import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.ts", "**/*.test.tsx"]}] 

Thus, imports from devDependencies are still logged as errors.

0
source

You devdeependencies are not used in production.

As I understand it, you still want to run your tests in production mode, right?

Therefore, it makes sense to have them in dependencies

-1
source

Source: https://habr.com/ru/post/1269540/


All Articles