Skip to content

useSingleCaseStatement

诊断类别:lint/style/useSingleCaseStatement

¥Diagnostic Category: lint/style/useSingleCaseStatement

自从:v1.0.0

¥Since: v1.0.0

强制 switch 子句只有一个语句,发出一个将语句封装在块中的快速修复。

¥Enforces switch clauses have a single statement, emits a quick fix wrapping the statements in a block.

¥Examples

¥Invalid

switch (foo) {
case true:
case false:
let foo = '';
foo;
}
code-block.js:4:9 lint/style/useSingleCaseStatement  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

A switch clause should only have a single statement.

2 │ case true:
3 │ case false:
> 4 │ let foo = ”;
^^^^^^^^^^^^^
> 5 │ foo;
^^^^
6 │ }
7 │

Unsafe fix: Wrap the statements in a block.

1 1 switch (foo) {
2 2 case true:
3 - ····case·false:
3+ ····case·false:·{
4 4 let foo = ”;
5 - ········foo;
5+ ········foo;
6+ ····}
6 7 }
7 8

¥Valid

switch (foo) {
case true:
case false: {
let foo = '';
foo;
}
}

¥Related links