]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-bitwise.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-bitwise.md
CommitLineData
eb39fafa
DC
1# disallow bitwise operators (no-bitwise)
2
3The use of bitwise operators in JavaScript is very rare and often `&` or `|` is simply a mistyped `&&` or `||`, which will lead to unexpected behavior.
4
5```js
6var x = y | z;
7```
8
9## Rule Details
10
11This rule disallows bitwise operators.
12
13Examples of **incorrect** code for this rule:
14
15```js
16/*eslint no-bitwise: "error"*/
17
18var x = y | z;
19
20var x = y & z;
21
22var x = y ^ z;
23
24var x = ~ z;
25
26var x = y << z;
27
28var x = y >> z;
29
30var x = y >>> z;
31
32x |= y;
33
34x &= y;
35
36x ^= y;
37
38x <<= y;
39
40x >>= y;
41
42x >>>= y;
43```
44
45Examples of **correct** code for this rule:
46
47```js
48/*eslint no-bitwise: "error"*/
49
50var x = y || z;
51
52var x = y && z;
53
54var x = y > z;
55
56var x = y < z;
57
58x += y;
59```
60
61## Options
62
63This rule has an object option:
64
65* `"allow"`: Allows a list of bitwise operators to be used as exceptions.
66* `"int32Hint"`: Allows the use of bitwise OR in `|0` pattern for type casting.
67
68### allow
69
70Examples of **correct** code for this rule with the `{ "allow": ["~"] }` option:
71
72```js
73/*eslint no-bitwise: ["error", { "allow": ["~"] }] */
74
75~[1,2,3].indexOf(1) === -1;
76```
77
78### int32Hint
79
80Examples of **correct** code for this rule with the `{ "int32Hint": true }` option:
81
82```js
83/*eslint no-bitwise: ["error", { "int32Hint": true }] */
84
85var b = a|0;
86```