no-bitwise
禁止按位运算符
JavaScript 中位运算符的使用非常少见,通常 &
或 |
只是一个错误的 &&
或 ||
,这将导致意外行为。
var x = y | z;
规则详情
此规则不允许按位运算符。
此规则的错误代码示例:
/*eslint no-bitwise: "error"*/
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;
x |= y;
x &= y;
x ^= y;
x <<= y;
x >>= y;
x >>>= y;
此规则的正确代码示例:
/*eslint no-bitwise: "error"*/
var x = y || z;
var x = y && z;
var x = y > z;
var x = y < z;
x += y;
选项
iUBjM40SPBc84UHpTbhTXi5m08Y+W8u+3M/WPQDUbA91GIF5tp6hcHbH4oIaa4GO
- hAjk05IEKh++biF/2hMM3bYZvmfsp3KK7+EVaw8B4XZla2YNxrmhdtq1jvuk5Ssv0zcFEVN29sCsrPGD4dr9hkf3fBQiqjJWjjF6lEZ134oq1sngnAUcC3wiOhWLvtk6hCygWqQ6p3NNvXWAzo4QtgAFX5Zi+d4HV0ZXqLyn4Y2yVQ1u9DXYDL17x47T6yslgL7zm5Tqb+F+6lYtlPjlb+z79pEPj1WS5OVUtV75zzLMWk5Srq5EgtF42v+Acc4s
allow
zsV3VIEaArmSNnLhUR0dD0ud+mvXlUoc4Q+o/uDILylDpvEH2+l00E2yNUYHGZuFXhy+1dmZ/jHmUqtxYU0kANKPP2NhqRFSO5hMBR8sENY=
/*eslint no-bitwise: ["error", { "allow": ["~"] }] */
~[1,2,3].indexOf(1) === -1;
int32Hint
zsV3VIEaArmSNnLhUR0dD34fcx3ltvDGeFBDx0/0aJk/oXPQzFVHkr53nEk1ibPbGf7wC6t7ybswhnKvUdkr9nhno1jrBIdLoJA2slS5I7wwi546cZMsWfeianNhkeUC
/*eslint no-bitwise: ["error", { "int32Hint": true }] */
var b = a|0;