]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/semi-style.md
first commit
[pve-eslint.git] / eslint / docs / rules / semi-style.md
1 # Enforce location of semicolons (semi-style)
2
3 Generally, semicolons are at the end of lines. However, in semicolon-less style, semicolons are at the beginning of lines. This rule enforces that semicolons are at the configured location.
4
5 ## Rule Details
6
7 This rule reports line terminators around semicolons.
8
9 This rule has an option.
10
11 ```json
12 {
13 "semi-style": ["error", "last"],
14 }
15 ```
16
17 - `"last"` (Default) enforces that semicolons are at the end of statements.
18 - `"first"` enforces that semicolons are at the beginning of statements. Semicolons of `for` loop heads (`for(a;b;c){}`) should be at the end of lines even if you use this option.
19
20 Examples of **incorrect** code for this rule with `"last"` option:
21
22 ```js
23 /*eslint semi-style: ["error", "last"]*/
24
25 foo()
26 ;[1, 2, 3].forEach(bar)
27
28 for (
29 var i = 0
30 ; i < 10
31 ; ++i
32 ) {
33 foo()
34 }
35 ```
36
37 Examples of **correct** code for this rule with `"last"` option:
38
39 ```js
40 /*eslint semi-style: ["error", "last"]*/
41
42 foo();
43 [1, 2, 3].forEach(bar)
44
45 for (
46 var i = 0;
47 i < 10;
48 ++i
49 ) {
50 foo()
51 }
52 ```
53
54 Examples of **incorrect** code for this rule with `"first"` option:
55
56 ```js
57 /*eslint semi-style: ["error", "first"]*/
58
59 foo();
60 [1, 2, 3].forEach(bar)
61
62 for (
63 var i = 0
64 ; i < 10
65 ; ++i
66 ) {
67 foo()
68 }
69 ```
70
71 Examples of **correct** code for this rule with `"first"` option:
72
73 ```js
74 /*eslint semi-style: ["error", "first"]*/
75
76 foo()
77 ;[1, 2, 3].forEach(bar)
78
79 for (
80 var i = 0;
81 i < 10;
82 ++i
83 ) {
84 foo()
85 }
86 ```
87
88 ## When Not To Use It
89
90 If you don't want to notify the location of semicolons, then it's safe to disable this rule.
91
92 ## Related rules
93
94 - [no-extra-semi](./no-extra-semi.md)
95 - [semi](./semi.md)
96 - [semi-spacing](./semi-spacing.md)