]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/space-infix-ops.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / space-infix-ops.md
CommitLineData
eb39fafa
DC
1# require spacing around infix operators (space-infix-ops)
2
3While formatting preferences are very personal, a number of style guides require spaces around operators, such as:
4
5```js
6var sum = 1 + 2;
7```
8
9The proponents of these extra spaces believe it make the code easier to read and can more easily highlight potential errors, such as:
10
11```js
12var sum = i+++2;
13```
14
15While this is valid JavaScript syntax, it is hard to determine what the author intended.
16
17## Rule Details
18
19This rule is aimed at ensuring there are spaces around infix operators.
20
21## Options
22
23This rule accepts a single options argument with the following defaults:
24
25```json
26"space-infix-ops": ["error", { "int32Hint": false }]
27```
28
29### `int32Hint`
30
31Set the `int32Hint` option to `true` (default is `false`) to allow write `a|0` without space.
32
33```js
34var foo = bar|0; // `foo` is forced to be signed 32 bit integer
35```
36
37Examples of **incorrect** code for this rule:
38
39```js
40/*eslint space-infix-ops: "error"*/
41/*eslint-env es6*/
42
43a+b
44
45a+ b
46
47a +b
48
49a?b:c
50
51const a={b:1};
52
53var {a=0}=bar;
54
55function foo(a=0) { }
56```
57
58Examples of **correct** code for this rule:
59
60```js
61/*eslint space-infix-ops: "error"*/
62/*eslint-env es6*/
63
64a + b
65
66a + b
67
68a ? b : c
69
70const a = {b:1};
71
72var {a = 0} = bar;
73
74function foo(a = 0) { }
75```
76
77## When Not To Use It
78
79You can turn this rule off if you are not concerned with the consistency of spacing around infix operators.