noDuplicateCase
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/suspicious/noDuplicateCase¥Diagnostic Category:
lint/suspicious/noDuplicateCase -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
no-duplicate-case相同¥Same as
no-duplicate-case
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noDuplicateCase": "error" } } }}¥Description
禁止重复的案例标签。
¥Disallow duplicate case labels.
如果 switch 语句在 case 子句中有重复的测试表达式,则程序员很可能复制了 case 子句但忘记更改测试表达式。
¥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
¥Invalid
switch (a) { case 1: break; case 1: break; default: break;}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:
switch (a) { case one: break; case one: break; default: break;}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:
switch (a) { case "1": break; case "1": break; default: break;}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”:
¥Valid
switch (a) { case 1: break; case 2: break; default: break;}switch (a) { case one: break; case two: break; default: break;}switch (a) { case "1": break; case "2": break; default: break;}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号