When I have this rule:
import/no-extraneous-dependencies: 2
...eslint complains if I try to import a devDependency in my code. Then, if I change my config to this:
import/no-extraneous-dependencies: [2, { devDependencies: true }]
...it stops complaining.
But the docs for this rule state that the devDependencies option defaults to true anyway, so I shouldn't have to set this explicitly. Either the docs are wrong or the defaults are wrong, or I've made a mistake somewhere.
I can confirm that the devDependencies option seems to default to false, whereas that documentation page says it defaults to true.
Yeah, this is confusing. The tests imply that it defaults to true as documented, but they could be bad tests... will need to look into it.
@jfmengels do you want to check this out?
Yeah, I meant to but I forgot to do it. Will try to look into it soon.
I can't reproduce this :confused:. Would someone be able to show me a repo where this fails, or create a failing test case (harder to do)?
Also, can you tell me the error message you got? Just want to make sure it was the dev dependency error message.
I can confirm this is the case. My eslintrc extends from airbnb-base (which disallows devDependencies imports) with the following simple content:
{
"extends": "airbnb-base",
"env": {
"browser": true,
"node": true,
"mocha": true
},
"rules": {
"no-console": 0,
"semi": [2, "never"],
"no-unexpected-multiline": 2
}
}
With the following file:
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)
chai.should()
It throws (as expected, due to airbnb-base's rule):
1:14 error 'chai' should be listed in the project's dependencies, not devDependencies
import/no-extraneous-dependencies
2:24 error 'chai-as-promised' should be listed in the project's dependencies, not devDependencies
import/no-extraneous-dependencies
However, adding "import/no-extraneous-dependencies": 2 does not resolve the error (this should override airbnb's rules, no?), while "import/no-extraneous-dependencies": [2, { "devDependencies": true }] does.
However, adding "import/no-extraneous-dependencies": 2 does not resolve the error (this should override airbnb's rules, no?), while "import/no-extraneous-dependencies": [2, { "devDependencies": true }] does.
This is exactly my experience. But I've looked into it further and I now think this might be a bug (or just surprising behaviour) in the way eslint handles overrides.
It looks like setting it to 2 doesn't reset the options, only the warning level.
You're right that explicitly setting the devDependencies fixes it:
rules:
import/no-extraneous-dependencies: [2, { devDependencies: true }]
But I've just noticed that an empty object also fixes it:
rules:
import/no-extraneous-dependencies: [2, { }]
So it looks like you have to pass in an empty object to eslint in order to get it to reset the options to defaults, otherwise it just retains whatever options the rule has previously had set (and just applies your new severity level).
Wild. So that closes this issue, then? Sounds like it's just confusion when extending the Airbnb config?
yup. opened an issue here; please go and upvote it!
turns out it's already a big debate going on here
My inline overrides have stopped working as well:
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
Any suggestions?
Most helpful comment
My inline overrides have stopped working as well:
Any suggestions?