简中文档

no-duplicate-case

NOTE: this rule is part of the 推荐 rule set.
Enable full set in deno.json:
{
  "lint": {
    "rules": {
      "tags": ["推荐"]
    }
  }
}
Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the include or exclude array in deno.json:
{
  "lint": {
    "rules": {
      "include": ["no-duplicate-case"],
      "exclude": ["no-duplicate-case"]
    }
  }
}

不允许在 switch 语句中重复使用相同的 case 子句。

当你在 switch 语句中重复使用一个 case 测试表达式时,重复的 case 将永远无法达到,这意味着这几乎总是一个错误。

无效:

const someText = "a";
switch (someText) {
  case "a": // (1)
    break;
  case "b":
    break;
  case "a": // (1) 的重复
    break;
  default:
    break;
}

有效:

const someText = "a";
switch (someText) {
  case "a":
    break;
  case "b":
    break;
  case "c":
    break;
  default:
    break;
}

你找到了你需要的东西吗?

编辑此页面
隐私政策