noBitwiseOperators
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
lint/suspicious/noBitwiseOperators¥Diagnostic Category:
lint/suspicious/noBitwiseOperators -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
no-bitwise相同¥Same as
no-bitwise
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noBitwiseOperators": "error" } } }}¥Description
禁止使用位运算符。
¥Disallow bitwise operators.
JavaScript 中很少使用位运算符,& 或 | 通常只是 && 或 || 的拼写错误,这会导致意外行为。
¥The use of bitwise operators in JavaScript is very rare and often & or | is simply a mistyped && or ||,
which will lead to unexpected behavior.
¥Examples
¥Invalid
let x = y | z;code-block.js:1:9 lint/suspicious/noBitwiseOperators ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Unexpected use of ’|‘.
> 1 │ let x = y | z;
│ ^^^^^
2 │
ℹ Did you mean || instead? If you want to use the bitwise operator, consider suppressing this diagnostic.
x |= y;code-block.js:1:1 lint/suspicious/noBitwiseOperators ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Unexpected use of ’|=‘.
> 1 │ x |= y;
│ ^^^^^^
2 │
ℹ Bitwise operators are prohibited because their use can be confusing or unintended. If you did want to use the bitwise operator, consider suppressing this diagnostic.
¥Valid
let x = y || z;let x = y && z;¥Options
该规则提供了如下所述的选项。
¥The rule provides the options described below.
允许使用位运算符列表作为异常。
¥Allows a list of bitwise operators to be used as exceptions.
{ "linter": { "rules": { "suspicious": { "noBitwiseOperators": { "options": { "allow": [ "&", "|", "^", "~", "<<", ">>", ">>>" ] } } } } }}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号