Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tleunen opened this issue Jul 7, 2016 · 21 comments
Closed

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

tleunen opened this issue Jul 7, 2016 · 21 comments

Comments

@tleunen
Copy link

tleunen commented Jul 7, 2016

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

@jfmengels
Copy link
Collaborator

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:

  • disable the rule in each file you want to disable it for using /* eslint-disable import/no-extraneous-dependencies */ at the top of your file
  • enable the rule in each file you want to enable it for using /* eslint import/no-extraneous-dependencies: ["error", {options: ...}] */ at the top of you file
  • (probably the safest option, as it's the only one that does not disable the rule for a whole file altogether) disable the line you want to ignore using `require('babel-core'); // eslint-disable-line import/no-extraneous-dependencies
  • or a combination of all the previous possibilities

Or my favorite, use glob based configurations eslint/eslint#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 eslint/eslint#3611 IMO.

Let me know if this answers your needs. If so, I'll close the issue :)

@tleunen
Copy link
Author

tleunen commented Jul 7, 2016

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 tleunen closed this as completed Jul 7, 2016
@benmosher
Copy link
Member

@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.

@tleunen
Copy link
Author

tleunen commented Jul 7, 2016

Yep, you're right, but since it's just 1 specific dependency, I'm ok with the comment ;)

@tristanbbq
Copy link
Contributor

@tleunen I had the same question. The Internet is small sometimes 😄

@benmosher
Copy link
Member

benmosher commented Sep 14, 2016

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 😅)

@benmosher benmosher added this to the 1.15.0 milestone Sep 14, 2016
@Willibaur
Copy link

Willibaur commented Apr 7, 2017

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

@ljharb
Copy link
Member

ljharb commented Apr 7, 2017

Is it listed in your package.json anywhere?

It'd be better to file a new issue, so we can debug it properly.

@benmosher
Copy link
Member

@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.

@benmosher
Copy link
Member

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.

@Willibaur
Copy link

@benmosher Thanks, It solved the issue

@siddhartharora02
Copy link

@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.

@benmosher
Copy link
Member

@siddhartharora02 I don't understand what you're describing but if you're experiencing issues, feel free to open a new issue.

@TaylorPzreal
Copy link

TaylorPzreal commented Dec 29, 2017

Simple to do:

"import/no-extraneous-dependencies": 0,

add this to rules

@ljharb
Copy link
Member

ljharb commented Dec 29, 2017

Sure, but then you're disabling this very useful rule.

AllanNozomu added a commit to mupi/masteraula-front that referenced this issue Jul 31, 2018
- fetch is not defined eslint/eslint#4015
- propTypes in dependencies import-js/eslint-plugin-import#422
Luis729 added a commit to NGCP/GCS that referenced this issue Mar 11, 2019
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 from the rule, see import-js/eslint-plugin-import#422
@clshortfuse

This comment was marked as off-topic.

@ljharb

This comment was marked as off-topic.

@clshortfuse

This comment was marked as off-topic.

@ljharb

This comment was marked as off-topic.

@clshortfuse

This comment was marked as off-topic.

@ljharb

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

9 participants