noBitwiseOperators
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noBitwiseOperators
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
no-bitwise
- Same as
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/nursery/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/nursery/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.
{ "options": { "allow": ["&", "|", "^", "~", "<<", ">>", ">>>"] }}
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noBitwiseOperators": "error" } } }}