noDuplicateCase
Este conteúdo não está disponível em sua língua ainda.
Diagnostic Category: lint/suspicious/noDuplicateCase
Since: v1.0.0
Sources:
- Same as:
no-duplicate-case
Disallow duplicate case labels.
If a switch statement has duplicate test expressions in case clauses, it is likely that a programmer copied a case clause but forgot to change the test expression.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:4:10 lint/suspicious/noDuplicateCase ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate case label.
2 │ case 1:
3 │ break;
> 4 │ case 1:
│ ^
5 │ break;
6 │ default:
ℹ The first similar label is here:
1 │ switch (a) {
> 2 │ case 1:
│ ^
3 │ break;
4 │ case 1:
code-block.js:4:10 lint/suspicious/noDuplicateCase ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate case label.
2 │ case one:
3 │ break;
> 4 │ case one:
│ ^^^
5 │ break;
6 │ default:
ℹ The first similar label is here:
1 │ switch (a) {
> 2 │ case one:
│ ^^^
3 │ break;
4 │ case one:
code-block.js:4:10 lint/suspicious/noDuplicateCase ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate case label.
2 │ case “1”:
3 │ break;
> 4 │ case “1”:
│ ^^^
5 │ break;
6 │ default:
ℹ The first similar label is here:
1 │ switch (a) {
> 2 │ case “1”:
│ ^^^
3 │ break;
4 │ case “1”: