noEqualsToNull
¥Summary
-
规则生效日期:
v2.3.8¥Rule available since:
v2.3.8 -
诊断类别:
lint/nursery/noEqualsToNull¥Diagnostic Category:
lint/nursery/noEqualsToNull -
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
no-eq-null相同¥Same as
no-eq-null
-
¥How to configure
{ "linter": { "rules": { "nursery": { "noEqualsToNull": "error" } } }}¥Description
要求使用 === 或 !== 与 null 进行比较。
¥Require the use of === or !== for comparison with null.
将 == 或 != 与 null 进行比较可能会产生意外结果,因为在比较 null 和 undefined 时,表达式的计算结果为 true。
¥Comparing to null with == or != may have unintended results as the
expression evaluates to true when comparing null to undefined.
¥Examples
¥Invalid
foo == null;code-block.js:1:5 lint/nursery/noEqualsToNull FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ null comparison with == is disallowed.
> 1 │ foo == null;
│ ^^
2 │
ℹ Unsafe fix: Use === instead.
1 │ foo·===·null;
│ +
foo != null;code-block.js:1:5 lint/nursery/noEqualsToNull FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ null comparison with != is disallowed.
> 1 │ foo != null;
│ ^^
2 │
ℹ Unsafe fix: Use !== instead.
1 │ foo·!==·null;
│ +
¥Valid
foo === null;foo !== null;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号