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
Would it be possible to not run no-extraneous-dependencies in specific directories/files?
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 (a src 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 :)
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!
@tleunen 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.
Yep, you're right, but since it's just 1 specific dependency, I'm ok with the comment ;)
@tleunen I had the same question. The Internet is small sometimes 馃槃
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 馃槄)
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
Is it listed in your package.json anywhere?
It'd be better to file a new issue, so we can debug it properly.
@Willibaur: if ember is a magic dependency (i.e. not listed in package.json), then you won't be able to use no-extraneous-dependencies, IIRC. It assumes a pretty standard npm/node view of the world.
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.
@benmosher Thanks, It solved the issue
@benmosher
In console it says an object was expected instead of an array, but it's working alright
vue.esm.js?efeb:571 [Vue warn]: Invalid value for option "components": expected an Object, but got Array.
@siddhartharora02 I don't understand what you're describing but if you're experiencing issues, feel free to open a new issue.
Simple to do:
"import/no-extraneous-dependencies": 0,
add this to rules
Sure, but then you're disabling this very useful rule.
Most helpful comment
@tleunen you could set the option
devDependencies: truein an.eslintrcin yourtestfolder:Then you'll get reports of any packages referenced that are not included
dependenciesordevDependencies. 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
testdirectory.