noBitwiseOperators
Summary
Section titled “Summary”- Rule available since:
v2.0.0 - Diagnostic Category:
lint/suspicious/noBitwiseOperators - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
no-bitwise
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noBitwiseOperators": "error" } } }}Description
Section titled “Description”Disallow bitwise operators.
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
Section titled “Examples”Invalid
Section titled “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.
let x = y || z;let x = y && z;Options
Section titled “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
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.