noDoubleEquals
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/suspicious/noDoubleEquals¥Diagnostic Category:
lint/suspicious/noDoubleEquals -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "noDoubleEquals": "error" } } }}¥Description
需要使用 === 和 !==。
¥Require the use of === and !==.
使用 == 而不是 === 进行比较通常是不好的做法。双运算符将触发隐式 类型强制,因此不推荐。使用严格相等运算符几乎总是最佳实践。
¥It is generally bad practice to use == for comparison instead of
===. Double operators will trigger implicit type coercion
and are thus not preferred. Using strict equality operators is almost
always best practice.
出于人机工程学原因,此规则默认将 == null 与 null 和 undefined 进行比较。
¥For ergonomic reasons, this rule makes by default an exception for == null for
comparing to both null and undefined.
¥Examples
¥Invalid
foo == barcode-block.js:1:5 lint/suspicious/noDoubleEquals FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Using == may be unsafe if you are relying on type coercion.
> 1 │ foo == bar
│ ^^
2 │
ℹ == is only allowed when comparing against null.
ℹ Unsafe fix: Use === instead.
1 │ foo·===·bar
│ +
¥Valid
foo == nullfoo != nullnull == foonull != foo¥Options
规则提供下面描述的选项。
¥The rule provides the option described below.
{ "//":"...", "options": { "ignoreNull": true }}ignoreNull
Section titled “ignoreNull”当此选项设置为 true 时,将对 null 进行检查,因为依赖双等号运算符与 null 进行比较通常用于检查与 null 或 undefined 的相等性。
¥When this option is set to true, an exception will be made for checking against null,
as relying on the double equals operator to compare with null is frequently used to check
equality with either null or undefined.
当选项设置为 false 时,所有双等号运算符都将被禁止,无一例外。
¥When the option is set to false, all double equal operators will be forbidden without
exceptions.
默认:true
¥Default: true
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号