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.

var x = 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 warnings:

var x = y | z;

var x = y & z;

var x = y ^ z;

var x = ~ z;

var x = y << z;

var x = y >> z;

var x = y >>> z;

var x |= y;

var x &= y;

var x ^= y;

var x <<= y;

var x >>= y;

var x >>>= y;

The following patterns are not considered warnings:

var x = y || z;

var x = y && z;

var x = y > z;

var x = y < z;

var x += y;

Version

This rule was introduced in ESLint 0.0.2.

Resources