1 | # comment-empty-line-before
|
2 |
|
3 | Require or disallow an empty line before comments.
|
4 |
|
5 |
|
6 | ```css
|
7 | a {}
|
8 | /* ← */
|
9 | /* comment */ /* ↑ */
|
10 | /** ↑
|
11 | * This line */
|
12 | ```
|
13 |
|
14 | This rule ignores:
|
15 |
|
16 | - comments that are the very first node in the source
|
17 | - shared-line comments
|
18 | - single-line comments with `//` (when you're using a custom syntax that supports them)
|
19 | - comments within selector and value lists
|
20 |
|
21 | The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule. We recommend to enable [`indentation`](../indentation/README.md) rule for better autofixing results with this rule.
|
22 |
|
23 | ## Options
|
24 |
|
25 | `string`: `"always"|"never"`
|
26 |
|
27 | ### `"always"`
|
28 |
|
29 | There _must always_ be an empty line before comments.
|
30 |
|
31 | The following patterns are considered violations:
|
32 |
|
33 |
|
34 | ```css
|
35 | a {}
|
36 | /* comment */
|
37 | ```
|
38 |
|
39 | The following patterns are _not_ considered violations:
|
40 |
|
41 |
|
42 | ```css
|
43 | a {}
|
44 |
|
45 | /* comment */
|
46 | ```
|
47 |
|
48 |
|
49 | ```css
|
50 | a {} /* comment */
|
51 | ```
|
52 |
|
53 | ### `"never"`
|
54 |
|
55 | There _must never_ be an empty line before comments.
|
56 |
|
57 | The following patterns are considered violations:
|
58 |
|
59 |
|
60 | ```css
|
61 | a {}
|
62 |
|
63 | /* comment */
|
64 | ```
|
65 |
|
66 | The following patterns are _not_ considered violations:
|
67 |
|
68 |
|
69 | ```css
|
70 | a {}
|
71 | /* comment */
|
72 | ```
|
73 |
|
74 |
|
75 | ```css
|
76 | a {} /* comment */
|
77 | ```
|
78 |
|
79 | ## Optional secondary options
|
80 |
|
81 | ### `except: ["first-nested"]`
|
82 |
|
83 | Reverse the primary option for comments that are nested and the first child of their parent node.
|
84 |
|
85 | For example, with `"always"`:
|
86 |
|
87 | The following patterns are considered violations:
|
88 |
|
89 |
|
90 | ```css
|
91 | a {
|
92 |
|
93 | /* comment */
|
94 | color: pink;
|
95 | }
|
96 | ```
|
97 |
|
98 | The following patterns are _not_ considered violations:
|
99 |
|
100 |
|
101 | ```css
|
102 | a {
|
103 | /* comment */
|
104 | color: pink;
|
105 | }
|
106 | ```
|
107 |
|
108 | ### `ignore: ["after-comment", "stylelint-commands"]`
|
109 |
|
110 | #### `"after-comment"`
|
111 |
|
112 | Ignore comments that follow another comment.
|
113 |
|
114 | For example, with `"always"`:
|
115 |
|
116 | The following patterns are _not_ considered violations:
|
117 |
|
118 |
|
119 | ```css
|
120 | a {
|
121 | background: pink;
|
122 |
|
123 | /* comment */
|
124 | /* comment */
|
125 | color: #eee;
|
126 | }
|
127 | ```
|
128 |
|
129 |
|
130 | ```css
|
131 | a {
|
132 | background: pink;
|
133 |
|
134 | /* comment */
|
135 |
|
136 | /* comment */
|
137 | color: #eee;
|
138 | }
|
139 | ```
|
140 |
|
141 | #### `"stylelint-commands"`
|
142 |
|
143 | Ignore comments that deliver commands to stylelint, e.g. `/* stylelint-disable color-no-hex */`.
|
144 |
|
145 | For example, with `"always"`:
|
146 |
|
147 | The following patterns are considered violations:
|
148 |
|
149 |
|
150 | ```css
|
151 | a {
|
152 | background: pink;
|
153 | /* not a stylelint command */
|
154 | color: #eee;
|
155 | }
|
156 | ```
|
157 |
|
158 | The following patterns are _not_ considered violations:
|
159 |
|
160 |
|
161 | ```css
|
162 | a {
|
163 | background: pink;
|
164 | /* stylelint-disable color-no-hex */
|
165 | color: pink;
|
166 | }
|
167 | ```
|