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

Cannot override rule in shared config #4079

Closed
chazzlabs opened this issue Oct 7, 2015 · 11 comments
Closed

Cannot override rule in shared config #4079

chazzlabs opened this issue Oct 7, 2015 · 11 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint

Comments

@chazzlabs
Copy link

ESLint v1.6.0

In my .eslintrc, I'm extending the AirBnb config and overriding a rule like this:

{
    "extends": "airbnb",
    "rules": {
        "indent": 2
    }
}

I couldn't find an example elsewhere, but eslint-config-airbnb v0.1.0 is overriding a rule the same way in its .eslintrc file so I assume what I have is correct. However, I'm seeing the following output when I run eslint scripts/**:

C:\dev\my-project\scripts\index.js
  2:5  error    Expected indentation of 2 space characters but found 4  indent
  2:5  warning  Unexpected console statement                            no-console

✖ 2 problems (1 error, 1 warning)
@ilyavolodin
Copy link
Member

Can you provide a code that is failing and also specify what did you expect to happen?

@ilyavolodin ilyavolodin added the question This issue asks a question about ESLint label Oct 7, 2015
@chazzlabs
Copy link
Author

@ilyavolodin Sure, sorry. The code is simply:

function run() {
    console.log('Hello, world');
}

exports.run = run;

The documentation for the indent rule (http://eslint.org/docs/rules/indent.html) says the default is 4 spaces and gives the example "indent": 2 for 4-space indentation, so I expected that overriding any extended configs using that configuration for the indent rule would make eslint pass for any files using 4-space indentation.

I've changed my .eslintrc to the following, specifying a number of spaces, and it works now:

{
    "extends": "airbnb",
    "rules": {
        "indent": [2, 4]
    }
}

Perhaps the default space setting for indentation is overridden elsewhere and I'm not aware of it or haven't found it.

@gyandeeps
Copy link
Member

Do you know what is the config of indent rule inside your extended config (airbnb)?

@hzoo
Copy link
Member

hzoo commented Oct 7, 2015

It's [2, 2] - I think it's just because the regular value is either 0, 1, 2. With an option you have to use [error value, config] so [2, 4] worked

Maybe the docs need to be updated

assert.deepEqual(config.rules.indent, [2, 2]);

@chazzlabs
Copy link
Author

Yes, the airbnb config has "indent": [2, 2]. Based on the docs I linked previously I assumed "indent": 2 would use a default of 4 spaces.

@gyandeeps
Copy link
Member

This is the expected behavior. If you just change the error level then we do inherit the options from the extended config.

@chazzlabs
Copy link
Author

Thanks, @gyandeeps. The only mention of overriding extended configs that I found was on http://eslint.org/docs/developer-guide/shareable-configs.html, and it only says, "You can override settings from the shareable config by adding them directly into your .eslintrc file."

@nzakas
Copy link
Member

nzakas commented Oct 7, 2015

It's mentioned on the primary configuration documentation: http://eslint.org/docs/user-guide/configuring#extending-configuration-files

@danny-andrews
Copy link
Contributor

danny-andrews commented May 12, 2016

This behavior still seems confusing to me, and (as far as I understand it) makes it impossible to override certain rule options (see #6144). Also, @nzakas, I don't see anywhere in the docs where it explains that rule options will be inherited from extended configs, just that rules can be overridden in the child configs. I was lead to believe that if you specified a rule in a child config, it would completely negate any rules of the same name in extended configs, resorting back to that rule's default options if none are specified.

@jsejcksn
Copy link

@nzakas Can you give us a response to what @danny-andrews brought up? It is very confusing.

@not-an-aardvark
Copy link
Member

not-an-aardvark commented Oct 30, 2016

This has been discussed in #6144 and #6361. It appears that the resolution of those discussions was also to leave the overriding behavior as-is. However, we are certainly open to PRs to improve the docs to hopefully make this less confusing.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 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 7, 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 question This issue asks a question about ESLint
Projects
None yet
Development

No branches or pull requests

8 participants