Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint should be listed in the project's dependencies, not devDependencies

Either I don't understand dependencies vs. devDependencies in node 100% yet or eslint is just wrong here (not capable of analyzing this correctly):

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

These are test dependencies, so why is it saying that they should be listed in dependencies?

Additional note: We're using Travis as our CI so I don't know if it makes a difference for that at all either.

like image 781
PositiveGuy Avatar asked Jul 06 '17 03:07

PositiveGuy


People also ask

Should Eslint be a dev dependency?

Packages like eslint are always a devDependency … unless, of course, you're building a CLI whose job is running eslint, in which case you'd add it as a dependency!

What is the difference between dependencies and devDependencies?

"dependencies" : Packages required by your application in production. "devDependencies" : Packages that are only needed for local development and testing.

Should Proptypes be a dev dependency?

javascript - 'prop-types' should be listed in the project's dependencies, not devDependencies - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Is react Dev dependency?

If you're building a React app, then react and react-dom would be dependencies . If you're using react-router for client-side routing, that would also be part of your dependencies . Any other packages like lodash or a design system library like Material UI ( @mui/material ) would also be dependencies .


2 Answers

Solved it with adding this to my .eslintrc:

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

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

Based on this user's reply:

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

rules: import/no-extraneous-dependencies: [error, { devDependencies: true }] Then you'll get reports of any packages referenced that are not included dependencies or devDependencies. Then you get the goodness of the rule, with no noise from the disable comments.

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

Also this post was helpful to confirm I wasn't insane to not want some of these in my dependencies list: Sharable ESLint Config

like image 70
PositiveGuy Avatar answered Oct 07 '22 09:10

PositiveGuy


If you want to allow imports of devDependencies in test files only you can use an array of globs, as the documentation of no-extraneous-dependencies states:

When using an array of globs, the setting will be set to true (no errors reported) if the name of the file being linted matches a single glob in the array, and false otherwise.

The following setting will disable the lint for test files only.

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

That way imports from devDependencies are still reported as errors.

like image 98
magic_al Avatar answered Oct 07 '22 10:10

magic_al