Cannot fix eslint rule on indenting case statements in switch statement
Solution 1:
I just saw that you made an edit ("EDIT 2") to your answer.
Anyway I wanted to advise you exactly that option:
"indent": ["error", 4, { "SwitchCase": 1 }]
Why do you consider it "an invalid rule for indent"?
According to the docs, it is the correct way to set the desired indent for switch
statements.
"SwitchCase" (default: 0) enforces indentation level for case clauses in switch statements.
The docs provide also [four examples]:
- Indent of 2 spaces with SwitchCase set to 0 will not indent case clauses with respect to switch statements.
- Indent of 2 spaces with SwitchCase set to 1 will indent case clauses with 2 spaces with respect to switch statements.
- Indent of 2 spaces with SwitchCase set to 2 will indent case clauses with 4 spaces with respect to switch statements.
- Indent of tab with SwitchCase set to 2 will indent case clauses with 2 tabs with respect to switch statements.
They are just examples, the fact that your target option object is not listed doesn't mean that it is not correct. And indeed it seems to be correct: ESLint Demo.
Your use case is actually included in the docs of the version 2.0.0 (no anchor to link directly, sorry, it it the last code block of the document):
/*eslint indent: [2, 4, {"SwitchCase": 1}]*/
switch(a){
case "a":
break;
case "b":
break;
}