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

The imports in tests for the rule import/no-extraneous-dependencies #959

Closed
Alex1990 opened this issue Jul 21, 2016 · 10 comments
Closed

The imports in tests for the rule import/no-extraneous-dependencies #959

Alex1990 opened this issue Jul 21, 2016 · 10 comments

Comments

@Alex1990
Copy link

Some of the dependencies in test code are in devDependencies. When I lint the test code, some errors appear:

  1:1  error  'chai' should be listed in the project's dependencies, not devDependencies  import/no-extraneous-dependencies

This error is unexpected.

@ljharb
Copy link
Collaborator

ljharb commented Jul 21, 2016

@Alex1990 the default is for the entire project, which is to only allow dependencies. The proper solution is to make a .eslintrc in your "test" folder, that overrides the rule to allow devDependencies also.

@Alex1990
Copy link
Author

Okay, so I must create two .eslintrc files.

@ljharb
Copy link
Collaborator

ljharb commented Jul 21, 2016

Yep! You probably already need one for your tests anyways, to enable the mocha env, or to allow for more nested callbacks than in your production code, etc :-)

@benoitgrelard
Copy link

Hi @ljharb, I was surprised by this too. I understand what you mean and it makes sense if you have a separate test folder with all your tests in it. However, in our situation we have interleaved source and test files. I guess that would be impossible until we get eslint/eslint#3611 with eslint?

So am I correct in thinking that the way forward for us is to override the rule to allow devDependencies?

@ljharb
Copy link
Collaborator

ljharb commented Aug 12, 2016

@artisologic unfortunately, that approach (interleaved source/test files) is incompatible with a great many tools. Indeed, until eslint/eslint#3611 is done, it's simply not practical to use eslint and also use that approach - so I'd recommend avoiding that approach until all of the tools you use support a glob-style configuration.

If you persist in interleaving tests and source, no matter how you configure this rule, you'll lose out on the most important benefit - ensuring that everything your source requires is explicitly listed as a dependency.

@knpwrs
Copy link
Contributor

knpwrs commented Sep 15, 2016

Worth noting, with the latest published version of eslint-plugin-import you can use globs to configure the no-extraneous-dependencies rule: import-js/eslint-plugin-import#527

@ljharb
Copy link
Collaborator

ljharb commented Sep 15, 2016

Yes, take a look at who filed the issue requesting it :-p import-js/eslint-plugin-import#470

This will be released as an update soon.

@SimenB
Copy link
Contributor

SimenB commented Oct 15, 2016

@ljharb It's been released a while now, are you going to update the default here (I can provide a PR for it)?

EDIT: nvm, just took a couple of mins: #1131

@ljharb
Copy link
Collaborator

ljharb commented Oct 15, 2016

@SimenB I'm waiting on import-js/eslint-plugin-import#602 / import-js/eslint-plugin-import#630, otherwise the globs have to be too accepting.

ljharb added a commit that referenced this issue Nov 6, 2016
@ljharb
Copy link
Collaborator

ljharb commented Nov 7, 2016

eslint-config-airbnb v13.0.0 is now released.

hibearpanda pushed a commit to 15Prospects/javascript that referenced this issue Jan 22, 2017
maoberlehner added a commit to avalanchesass/avalanche that referenced this issue May 1, 2017
- Remove comma-dangle rule because of reasons stated by airbnb
- Require strict because of reasons stated by airbnb
- Do not allow importing devDependencies because a separate eslint config file should be used for tests (airbnb/javascript#959 (comment))
jaylaw81 pushed a commit to appirio-digital/ads-best-practices that referenced this issue Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants