]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/block-spacing.md
99b354016e3577b5f7b16b92e4458807db799ee1
[pve-eslint.git] / eslint / docs / src / rules / block-spacing.md
1 ---
2 title: block-spacing
3 layout: doc
4 rule_type: layout
5 related_rules:
6 - space-before-blocks
7 - brace-style
8 ---
9
10
11
12 ## Rule Details
13
14 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.
15
16 ## Options
17
18 This rule has a string option:
19
20 * `"always"` (default) requires one or more spaces
21 * `"never"` disallows spaces
22
23 ### always
24
25 Examples of **incorrect** code for this rule with the default `"always"` option:
26
27 :::incorrect
28
29 ```js
30 /*eslint block-spacing: "error"*/
31
32 function foo() {return true;}
33 if (foo) { bar = 0;}
34 function baz() {let i = 0;
35 return i;
36 }
37
38 class C {
39 static {this.bar = 0;}
40 }
41 ```
42
43 :::
44
45 Examples of **correct** code for this rule with the default `"always"` option:
46
47 :::correct
48
49 ```js
50 /*eslint block-spacing: "error"*/
51
52 function foo() { return true; }
53 if (foo) { bar = 0; }
54
55 class C {
56 static { this.bar = 0; }
57 }
58 ```
59
60 :::
61
62 ### never
63
64 Examples of **incorrect** code for this rule with the `"never"` option:
65
66 :::incorrect
67
68 ```js
69 /*eslint block-spacing: ["error", "never"]*/
70
71 function foo() { return true; }
72 if (foo) { bar = 0;}
73
74 class C {
75 static { this.bar = 0; }
76 }
77 ```
78
79 :::
80
81 Examples of **correct** code for this rule with the `"never"` option:
82
83 :::correct
84
85 ```js
86 /*eslint block-spacing: ["error", "never"]*/
87
88 function foo() {return true;}
89 if (foo) {bar = 0;}
90
91 class C {
92 static {this.bar = 0;}
93 }
94 ```
95
96 :::
97
98 ## When Not To Use It
99
100 If you don't want to be notified about spacing style inside of blocks, you can safely disable this rule.