no-compare-neg-zero
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-compare-neg-zero"],
"exclude": ["no-compare-neg-zero"]
}
}
}不允许与负零(-0)进行比较。
直接将一个值与负数进行比较可能不会按预期工作,因为它也会对非负零(即0和+0)通过。可以使用 Object.is 进行与负零的显式比较。
无效:
if (x === -0) {}
有效:
if (x === 0) {}
if (Object.is(x, -0)) {}