]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/spaced-line-comment.md
first commit
[pve-eslint.git] / eslint / docs / rules / spaced-line-comment.md
1 # spaced-line-comment: enforce consistent spacing after `//` in line comments
2
3 (removed) This rule was **removed** in ESLint v1.0 and **replaced** by the [spaced-comment](spaced-comment.md) rule.
4
5 Some style guides require or disallow a whitespace immediately after the initial `//` of a line comment.
6 Whitespace after the `//` makes it easier to read text in comments.
7 On the other hand, commenting out code is easier without having to put a whitespace right after the `//`.
8
9
10 ## Rule Details
11
12 This rule will enforce consistency of spacing after the start of a line comment `//`.
13
14 This rule takes two arguments. If the first is `"always"` then the `//` must be followed by at least once whitespace.
15 If `"never"` then there should be no whitespace following.
16 The default is `"always"`.
17
18 The second argument is an object with one key, `"exceptions"`.
19 The value is an array of string patterns which are considered exceptions to the rule.
20 It is important to note that the exceptions are ignored if the first argument is `"never"`.
21 Exceptions cannot be mixed.
22
23 Examples of **incorrect** code for this rule:
24
25 ```js
26 // When ["never"]
27 // This is a comment with a whitespace at the beginning
28 ```
29
30 ```js
31 //When ["always"]
32 //This is a comment with no whitespace at the beginning
33 var foo = 5;
34 ```
35
36 ```js
37 // When ["always",{"exceptions":["-","+"]}]
38 //------++++++++
39 // Comment block
40 //------++++++++
41 ```
42
43 Examples of **correct** code for this rule:
44
45 ```js
46 // When ["always"]
47 // This is a comment with a whitespace at the beginning
48 var foo = 5;
49 ```
50
51 ```js
52 //When ["never"]
53 //This is a comment with no whitespace at the beginning
54 var foo = 5;
55 ```
56
57 ```js
58 // When ["always",{"exceptions":["-"]}]
59 //--------------
60 // Comment block
61 //--------------
62 ```
63
64 ```js
65 // When ["always",{"exceptions":["-+"]}]
66 //-+-+-+-+-+-+-+
67 // Comment block
68 //-+-+-+-+-+-+-+
69 ```
70
71 ## Related Rules
72
73 * [spaced-comment](spaced-comment.md)