]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/block-spacing.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / block-spacing.md
1 # Disallow or enforce spaces inside of blocks after opening block and before closing block (block-spacing)
2
3 ## Rule Details
4
5 This rule enforces consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line.
6
7 ## Options
8
9 This rule has a string option:
10
11 * `"always"` (default) requires one or more spaces
12 * `"never"` disallows spaces
13
14 ### always
15
16 Examples of **incorrect** code for this rule with the default `"always"` option:
17
18 ```js
19 /*eslint block-spacing: "error"*/
20
21 function foo() {return true;}
22 if (foo) { bar = 0;}
23 function baz() {let i = 0;
24 return i;
25 }
26
27 class C {
28 static {this.bar = 0;}
29 }
30 ```
31
32 Examples of **correct** code for this rule with the default `"always"` option:
33
34 ```js
35 /*eslint block-spacing: "error"*/
36
37 function foo() { return true; }
38 if (foo) { bar = 0; }
39
40 class C {
41 static { this.bar = 0; }
42 }
43 ```
44
45 ### never
46
47 Examples of **incorrect** code for this rule with the `"never"` option:
48
49 ```js
50 /*eslint block-spacing: ["error", "never"]*/
51
52 function foo() { return true; }
53 if (foo) { bar = 0;}
54
55 class C {
56 static { this.bar = 0; }
57 }
58 ```
59
60 Examples of **correct** code for this rule with the `"never"` option:
61
62 ```js
63 /*eslint block-spacing: ["error", "never"]*/
64
65 function foo() {return true;}
66 if (foo) {bar = 0;}
67
68 class C {
69 static {this.bar = 0;}
70 }
71 ```
72
73 ## When Not To Use It
74
75 If you don't want to be notified about spacing style inside of blocks, you can safely disable this rule.