Disallow Bitwise Operators (no-bitwise)

The use of bitwise operators in JavaScript is very rare and often & or | is simply a mistyped && or ||, which will lead to unexpected behavior.

varx=y|z;

Rule Details

This rule is aimed at catching typos that end up as bitwise operators, but are meant to be the much more common &&, ‘

’, <, > operators. As such, it will warn whenever it encounters a bitwise operator:

The following patterns are considered problems:

/*eslint no-bitwise: 2*/varx=y|z;/*error Unexpected use of '|'.*/varx=y&z;/*error Unexpected use of '&'.*/varx=y^z;/*error Unexpected use of '^'.*/varx=~z;/*error Unexpected use of '~'.*/varx=y<<z;/*error Unexpected use of '<<'.*/varx=y>>z;/*error Unexpected use of '>>'.*/varx=y>>>z;/*error Unexpected use of '>>>'.*/x|=y;/*error Unexpected use of '|='.*/x&=y;/*error Unexpected use of '&='.*/x^=y;/*error Unexpected use of '^='.*/x<<=y;/*error Unexpected use of '<<='.*/x>>=y;/*error Unexpected use of '>>='.*/x>>>=y;/*error Unexpected use of '>>>='.*/

The following patterns are not considered problems:

/*eslint no-bitwise: 2*/varx=y||z;varx=y&&z;varx=y>z;varx=y<z;x+=y;

Options

This rule supports the following options:

allow: The list of bitwise operators to be used as exceptions to the rule. For example: