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 DescriptionDisallow 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 ExamplesInvalid
Section titled Invalidlet 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.
Valid
Section titled Validlet x = y || z;
let x = y && z;
Options
Section titled OptionsThe rule provides the options described below.
allow
Section titled allowAllows 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" } } }}