deno.com

禁止重复 else if

注意:此规则是recommended规则集的一部分。
deno.json 中启用完整集合
{
  "lint": {
    "rules": {
      "tags": ["recommended"]
    }
  }
}
使用 Deno CLI 启用完整集合
deno lint --rules-tags=recommended
通过将其添加到deno.json中的includeexclude数组,可以将此规则明确地包含或排除在当前标签中存在的规则之外。
{
  "lint": {
    "rules": {
      "include": ["no-dupe-else-if"],
      "exclude": ["no-dupe-else-if"]
    }
  }
}

禁止在if/else if语句中两次使用相同的条件。

当您在if/else if语句中重复使用一个条件时,重复的条件将永远不会被触发(除非有异常的副作用),这意味着这几乎总是一个错误。

无效示例

if (a) {}
else if (b) {}
else if (a) {} // duplicate of condition above

if (a === 5) {}
else if (a === 6) {}
else if (a === 5) {} // duplicate of condition above

有效示例

if (a) {}
else if (b) {}
else if (c) {}

if (a === 5) {}
else if (a === 6) {}
else if (a === 7) {}

您找到所需内容了吗?

隐私政策