简中文档

no-extra-boolean-cast

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-extra-boolean-cast"],
      "exclude": ["no-extra-boolean-cast"]
    }
  }
}

禁止不必要的布尔类型强制转换。

在某些上下文中,例如 ifwhilefor 语句,表达式会自动转为布尔值。因此,像双重否定 (!!foo) 或强制转换 (Boolean(foo)) 这样的技术是多余的,并且与不进行否定或强制转换得到的结果相同。

无效:

if (!!foo) {}
if (Boolean(foo)) {}
while (!!foo) {}
for (; Boolean(foo);) {}

有效:

if (foo) {}
while (foo) {}
for (; foo;) {}

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

编辑此页面
隐私政策