question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Indent rule: unable to enforce indentation of switch cases [$15 awarded]

See original GitHub issue

The following code results in having no errors:

eslint --reset --no-eslintrc --rule "{indent: 2}" test.js

switch (a) {
case '1':
b();
break;
default:
c();
break;
}

If I enable the indentSwitchCase option I get the following errors: eslint --reset --no-eslintrc --rule "{indent: [2, 4, {indentSwitchCase: true}]}" test.js

test.js
  3:4  error  Expected indentation of 4 characters  indent
  6:4  error  Expected indentation of 4 characters  indent

I would expect the following errors:

test.js
  2:4  error  Expected indentation of 4 characters  indent
  3:8  error  Expected indentation of 8 characters  indent
  4:8  error  Expected indentation of 8 characters  indent
  5:4  error  Expected indentation of 4 characters  indent
  6:8  error  Expected indentation of 8 characters  indent
  7:8  error  Expected indentation of 8 characters  indent

It seems like the indentSwitchCase option enables the indentation check only of the body of a SwitchCase statement. The Indentation of the whole SwitchCase statement is recognized by the rule itself and only validated to be consistet within an single switch statement. There is no option to confiugre a consistent identation for SwitchCase statements of a whole file.

The other strange behavior with this option is, when I explecitly set the value to false it doesn’t forbid the identation for a SwitchCase body, it just ignores those lines.

<bountysource-plugin>

The $15 bounty on this issue has been claimed at Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

80reactions
mgenwarecommented, Jan 2, 2016

@fourq try this:

"indent": [2, 2, {"SwitchCase": 1}]

More info

0reactions
xyzdatacommented, Jun 29, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Indent rule: unable to enforce indentation of switch cases
Indent rule : unable to enforce indentation of switch cases [$15 awarded]
Read more >
Cannot fix eslint rule on indenting case statements in switch ...
The eslintrc.js that was automagically generated for me has indent: ["error", "tab"] How do I implement SwitchCase ?
Read more >
indent - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
D43183 clang-format: introduce `CaseBlockIndent` to ... - LLVM
When a block is started after a case label, clang-format does add extra indent to the content of this block: the block content...
Read more >
Linux kernel coding style
Coding style is very personal, and I won't force my views on anybody, ... In short, 8-char indents make things easier to read,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found