Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eslint allow extraneous dependencies in tests

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?

like image 831
jeff Avatar asked Jul 27 '17 09:07

jeff


People also ask

How do I enable ESLint analysis in ESLint?

ESLint requires ESLint configuration files ( .eslintrc.* files) under your projects Although the ESLint analysis fails by any reasons, you can see the analysis results of DeepScan without an interruption. By default, ESLint analysis is disabled. To enable it, do the following: DeepScan supports ESLint version 5, 6, and 7.

What are the ESLint configuration files needed for Deepscan?

ESLint requires ESLint configuration files ( .eslintrc.* files) under your projects Although the ESLint analysis fails by any reasons, you can see the analysis results of DeepScan without an interruption. By default, ESLint analysis is disabled.

How do I test if a package is not included dependencies?

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.

What options does this rule support for importing dependencies?

This rule supports the following options: devDependencies: If set to false, then the rule will show an error when devDependencies are imported. Defaults to true. optionalDependencies: If set to false, then the rule will show an error when optionalDependencies are imported.


1 Answers

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"]}]
like image 65
YouEyeK Avatar answered Nov 15 '22 14:11

YouEyeK