12

In my test files I get eslint error on some imports like

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

this happens only in my second tests directory in some subfolder
in my root tests directory I don't get this errors
I didn't find any settings in package.json or .eslintrc which could cause differentiation.
Currently I have to use

/* eslint-disable import/no-extraneous-dependencies*/

in my test files which we don't like
If I add

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

to .eslintrc th rule is off everywhere not just in tests
How can I switch this rule of except of placing .eslintrc to the tests folder? which folders use devDependencies?

jeff
  • 1,169
  • 1
  • 19
  • 44

2 Answers2

24

You can use an array of globs as follows, which will allow extraneous dependencies to be access from test files where file name matches **/*.test.js

"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js"]}]
YouEyeK
  • 890
  • 8
  • 8
  • If using jest, adding `"env": { "jest": true}` to your `eslintrc.json` also works. See [this thread](https://stackoverflow.com/questions/44611190/using-jest-in-my-react-app-describe-is-not-defined) – Lucas David Mar 18 '23 at 08:47
-2

You can create a .eslintignore file in the project root to disable ESLint for specific files or directories.

And put the following line into it:

test/*

Reference: http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories


Edit:

If you want to ignore a specific rule for a particular directory, you can put another .eslintrc file in that directory.

Reference: http://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy

Chris Lam
  • 3,526
  • 13
  • 10