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

Overriding a rule doesn't reset options, unless you pass an empty object #6955

Closed
callumlocke opened this issue Aug 22, 2016 · 4 comments
Closed
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon

Comments

@callumlocke
Copy link

callumlocke commented Aug 22, 2016

What version of ESLint are you using?

3.3.1

What parser (default, Babel-ESLint, etc.) are you using?

babel-eslint

Please show your full configuration:

root: true
extends: airbnb
parser: babel-eslint
rules:
  no-console: 0
  import/no-extraneous-dependencies: 2

What did you do? Please include the actual source code causing the issue.

I added import/no-extraneous-dependencies: 2 to my config.

What did you expect to happen?

I thought this would override the default setting from airbnb, which is [2, { devDependencies: false }].

I assumed my 2 would receive the default options, which include devDependencies: true.

What actually happened? Please include the actual, raw output from ESLint.

Instead, the original options from the eslint-config-airbnb were retained. ESLint behaved as if I had set devDependencies: false.

I found it's necessary to pass an empty object just to get the defaults back:

  import/no-extraneous-dependencies: [2, {}]

Notes

I guess it might be by design, but I think it's very surprising that 2 behaves completely differently from [2, {}].

Before I worked out the root cause, I posted this issue on eslint-plugin-import, and a few people commented saying they'd had exactly the same problem. So it seems like a lot of people are confused by this behaviour.

@mysticatea
Copy link
Member

Thank you for this issue.

I think this is intentional behavior.
This is duplicate of #6144 and #6361.

@callumlocke
Copy link
Author

callumlocke commented Aug 22, 2016

OK. I think it could be worth revising this behaviour for the next major version bump. It's evidently a very weird, surprising behaviour. In this issue it's only on revisiting it a third time that I eventually traced the problem to eslint's own behaviour. Several others also made the same assumption as me: that there's no way in hell eslint would work like that, so it must be a problem with the plugin we were using.

If I override a rule in my local config, and it's not working correctly, I go and look at that rule's documentation to see what its options (and defaults) are. But it turns out it doesn't work like that, instead eslint assembles a mixture of my severity level with the other options from the other config – unless I pass in an empty object (wtf!). It's very confusing for virtually zero convenience (letting me set a severity but magically importing the other options from the other config?). I'd understand if eslint's behaviour was to merge my options over those from the other config, but it doesn't do that either. It uses the other config's options if I provide nothing, but not if I provide an empty object. It's very un-idiomatic.

@platinumazure
Copy link
Member

I've said before that I don't like this behavior and think it should be changed. Can we reopen this and consider it a breaking but worthwhile change?

@jfo84
Copy link
Contributor

jfo84 commented Dec 27, 2016

Seconded @platinumazure

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

5 participants