noUselessSwitchCase
此内容尚不支持你的语言。
Diagnostic Category: lint/complexity/noUselessSwitchCase
Since: v1.0.0
Sources:
- Same as:
unicorn/no-useless-switch-case
Disallow useless case
in switch
statements.
A switch
statement can optionally have a default
clause.
The default
clause will be still executed only if there is no match in the case
clauses.
An empty case
clause that precedes the default
clause is thus useless.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:2:5 lint/complexity/noUselessSwitchCase FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Useless case clause.
1 │ switch (foo) {
> 2 │ case 0:
│ ^^^^^^^
3 │ default:
4 │ break;
ℹ because the default clause is present:
1 │ switch (foo) {
2 │ case 0:
> 3 │ default:
│ ^^^^^^^^
> 4 │ break;
│ ^^^^^^
5 │ case 1:
6 │ break;
ℹ Unsafe fix: Remove the useless case.
1 1 │ switch (foo) {
2 │ - ····case·0:
3 2 │ default:
4 3 │ break;
code-block.js:3:5 lint/complexity/noUselessSwitchCase FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Useless case clause.
1 │ switch (foo) {
2 │ default:
> 3 │ case 0:
│ ^^^^^^^
> 4 │ break;
│ ^^^^^^
5 │ case 1:
6 │ break;
ℹ because the default clause is present:
1 │ switch (foo) {
> 2 │ default:
│ ^^^^^^^^
3 │ case 0:
4 │ break;
ℹ Unsafe fix: Remove the useless case.
1 1 │ switch (foo) {
2 │ - ····default:
3 │ - ····case·0:
2 │ + ····default:
4 3 │ break;
5 4 │ case 1: