deno.com

no-dupe-else-if

注意: 此规则是 recommended 规则集的一部分。
deno.json 中启用完整规则集
{
  "lint": {
    "tags": ["recommended"]
  }
}
使用 Deno CLI 启用完整规则集
deno lint --tags=recommended

禁止在 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) {}

您找到您需要的内容了吗?

隐私政策