Skip to content

noEqualsToNull

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"nursery": {
"noEqualsToNull": "error"
}
}
}
}

¥Description

要求使用 ===!==null 进行比较。

¥Require the use of === or !== for comparison with null.

==!=null 进行比较可能会产生意外结果,因为在比较 nullundefined 时,表达式的计算结果为 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