eslint-plugin-import: [no-extraneous-dependencies] Add exceptions?
For a specific package, I’m importing babel-core
in my test files, but babel-core
is set as a devDep because I’m compiling the files before publishing my package. Therefore, there’s no reason to put the module as a direct dependency.
~/dev/babel-plugin-module-alias/test/index.js
4:1 error 'babel-core' should be listed in the project's dependencies, not devDependencies import/no-extraneous-dependencies
Would it be possible to not run no-extraneous-dependencies
in specific directories/files?? Like test.js
, test/**/*.js
, __tests__/**/*.js
, **/*.test.js
or **/*.spec.js
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 21 (11 by maintainers)
Commits related to this issue
- Fix some eslint warning - fetch is not defined https://github.com/eslint/eslint/issues/4015 - propTypes in dependencies https://github.com/benmosher/eslint-plugin-import/issues/422 — committed to mupi/masteraula-front by AllanNozomu 6 years ago
- Removed comments from eslint-disable Pretty sure that only rules are only supposed to be placed there. Developer can figure out the reason why that rule is there. Was not able to exclude electron fr... — committed to NGCP/GCS by Luis729 5 years ago
Simple to do:
add this to rules
@tleunen you could set the option
devDependencies: true
in an.eslintrc
in yourtest
folder:Then you’ll get reports of any packages referenced that are not included
dependencies
ordevDependencies
. 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.actually, scratch that: you may be able to specify
"import/core-modules": [ "ember" ]
in your.eslintrc.js
.refer to the import/core-modules docs for more info.
You can, in some cases, but this is a limitation of ESLint. If you want to disable the rule in a folder, you can add a
.eslintrc
file at the root of that folder where you disable the rule. Or the other way around: disable it by default in your root config, and activate it using a.eslintrc
file where appropriate (asrc
folder for instance).The other options are to:
/* eslint-disable import/no-extraneous-dependencies */
at the top of your file/* eslint import/no-extraneous-dependencies: ["error", {options: ...}] */
at the top of you fileOr my favorite, use glob based configurations https://github.com/eslint/eslint/issues/3611. Unfortunately, that is not yet implemented 😕 (should you be using
XO
, then it is)Of course, we could disable the rule in the code if we notice that the file in question is in some directory, but this could be applied to so many rules that it’s better to invest time to make it work in https://github.com/eslint/eslint/issues/3611 IMO.
Let me know if this answers your needs. If so, I’ll close the issue 😃
Sure, but then you’re disabling this very useful rule.
FWIW: v1.15.0 shipped with #527, which allows globs in addition to booleans for the various dependency flavors. Docs here: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md#options
(apparently we changed our minds 😅)
@Willibaur: if
ember
is a magic dependency (i.e. not listed inpackage.json
), then you won’t be able to useno-extraneous-dependencies
, IIRC. It assumes a pretty standardnpm
/node
view of the world.Hi all, I’ve been through many of the Issues on this repo, and could not find what I’m looking for so I’m going to leave my question here, I have this rule in my
.eslintrc.js
'import/no-extraneous-dependencies': ["error", { devDependencies: true, }],
But is still giving my a bunch of errors, all of them like this one
1:1 error 'ember' should be listed in the project's dependencies. Run 'npm i -S ember' to add it import/no-extraneous-dependencies
Any help would be appreciated Thanks in advance
@tleunen I had the same question. The Internet is small sometimes 😄
Yep I was using the comment to disable it, I’m ok 😃
I thought it was potentially an error in the rule but everything is ok if you suggest using the comment anyway 😃 Thanks!