]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/space-after-keywords.md
ac619ed0e5d07516dadfc53166f83f7f8f6ad29f
[pve-eslint.git] / eslint / docs / src / rules / space-after-keywords.md
1 ---
2 title: space-after-keywords
3 layout: doc
4
5 ---
6
7 Enforces consistent spacing after keywords.
8
9 (removed) This rule was **removed** in ESLint v2.0 and replaced by the [keyword-spacing](keyword-spacing) rule.
10
11 (fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#--fix) automatically fixed problems reported by this rule.
12
13 Some style guides will require or disallow spaces following the certain keywords.
14
15 ```js
16 if (condition) {
17 doSomething();
18 } else {
19 doSomethingElse();
20 }
21
22 if(condition) {
23 doSomething();
24 }else{
25 doSomethingElse();
26 }
27 ```
28
29 ## Rule Details
30
31 This rule will enforce consistency of spacing after the keywords `if`, `else`, `for`, `while`, `do`, `switch`, `try`, `catch`, `finally`, and `with`.
32
33 This rule takes one argument. If it is `"always"` then the keywords must be followed by at least one space. If `"never"`
34 then there should be no spaces following. The default is `"always"`.
35
36 Examples of **incorrect** code for this rule:
37
38 ::: incorrect
39
40 ```js
41 /*eslint space-after-keywords: "error"*/
42
43 if(a) {}
44
45 if (a) {} else{}
46
47 do{} while (a);
48 ```
49
50 :::
51
52 ::: incorrect
53
54 ```js
55 /*eslint space-after-keywords: ["error", "never"]*/
56
57 if (a) {}
58 ```
59
60 :::
61
62 Examples of **correct** code for this rule:
63
64 ::: correct
65
66 ```js
67 /*eslint space-after-keywords: "error"*/
68
69 if (a) {}
70
71 if (a) {} else {}
72 ```
73
74 :::
75
76 ::: correct
77
78 ```js
79 /*eslint space-after-keywords: ["error", "never"]*/
80
81 if(a) {}
82 ```
83
84 :::