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

Inconsistent indentation allowed on chained if-else #6956

Closed
matt-fff opened this issue Aug 22, 2016 · 2 comments
Closed

Inconsistent indentation allowed on chained if-else #6956

matt-fff opened this issue Aug 22, 2016 · 2 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@matt-fff
Copy link

matt-fff commented Aug 22, 2016

What version of ESLint are you using?
v3.3.1

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

Please show your full configuration:

{
  "env": {
    "node": true,
    "es6": true,
    "mocha": true
  },
  "rules": {
    "no-bitwise": 2,
    "curly": 0,
    "indent": [
      2,
      2,
      {
        "SwitchCase": 1
      }
    ],
    "no-caller": 2,
    "quotes": [
      2,
      "single"
    ],
    "no-undef": 2,
    "no-unused-vars": 2,
    "strict": 0,
    "max-len": [
      2,
      {
        "code": 100,
        "ignoreComments": true
      }
    ],
    "no-use-before-define": 0,
    "new-cap": 2,
    "no-sparse-arrays": 0,
    "no-trailing-spaces": 2
  },
  "parserOptions": {
    "sourceType": "module"
  }
}

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

  if (type === '1') abacus.inc('rest.status.info');
    else if (type === '2') abacus.inc('rest.status.ok');
  else if (type === '4') abacus.inc('rest.status.clientError');
  else if (type === '5') abacus.inc('rest.status.serverError');

With the above if-else chain, I have the first else indented too far and we get the correct output: error Expected indentation of 2 space characters but found 4 indent

But if the first else is correct, I find that all subsequent lines in the if-else chain don't generate errors when their indentation is off.

  if (type === '1') abacus.inc('rest.status.info');
  else if (type === '2') abacus.inc('rest.status.ok');
               else if (type === '4') abacus.inc('rest.status.clientError');
      else if (type === '5') abacus.inc('rest.status.serverError');

This generates no output and linting passes.

What did you expect to happen?
I would expect the second input to generate indentation errors:

error  Expected indentation of 2 space characters but found 15  indent
error  Expected indentation of 2 space characters but found 6  indent

What actually happened? Please include the actual, raw output from ESLint.
Linting passes and generates no output.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 22, 2016
@vitorbal
Copy link
Member

Thanks for the report, @whimatthew! I can reproduce this. Seems like all else statements after the first one are not triggering an indentation error.

@vitorbal vitorbal added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Aug 22, 2016
@not-an-aardvark
Copy link
Member

Working on this.

not-an-aardvark added a commit to not-an-aardvark/eslint that referenced this issue Aug 24, 2016
not-an-aardvark added a commit to not-an-aardvark/eslint that referenced this issue Aug 24, 2016
@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
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants