Indent rule: unable to enforce indentation of switch cases [$15 awarded]
See original GitHub issueThe 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:
- Created 9 years ago
- Reactions:1
- Comments:11 (6 by maintainers)
Top GitHub Comments
@fourq try this:
More info
"indent": ["error", 4],
https://gist.github.com/xgqfrms-gildata/7d861fde6dd15262ae007e68ca0898f0