1 | # rule-empty-line-before
|
2 |
|
3 | Require or disallow an empty line before rules.
|
4 |
|
5 |
|
6 | ```css
|
7 | a {}
|
8 | /* ← */
|
9 | b {} /* ↑ */
|
10 | /** ↑
|
11 | * This line */
|
12 | ```
|
13 |
|
14 | This rule ignores rules that are the very first node in a source.
|
15 |
|
16 | 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.
|
17 |
|
18 | ## Options
|
19 |
|
20 | `string`: `"always"|"never"|"always-multi-line"|"never-multi-line"`
|
21 |
|
22 | ### `"always"`
|
23 |
|
24 | There _must always_ be an empty line before rules.
|
25 |
|
26 | The following patterns are considered problems:
|
27 |
|
28 |
|
29 | ```css
|
30 | a {} b {}
|
31 | ```
|
32 |
|
33 |
|
34 | ```css
|
35 | a {}
|
36 | b {}
|
37 | ```
|
38 |
|
39 | The following patterns are _not_ considered problems:
|
40 |
|
41 |
|
42 | ```css
|
43 | a {}
|
44 |
|
45 | b {}
|
46 | ```
|
47 |
|
48 | ### `"never"`
|
49 |
|
50 | There _must never_ be an empty line before rules.
|
51 |
|
52 | The following patterns are considered problems:
|
53 |
|
54 |
|
55 | ```css
|
56 | a {}
|
57 |
|
58 | b {}
|
59 | ```
|
60 |
|
61 | The following patterns are _not_ considered problems:
|
62 |
|
63 |
|
64 | ```css
|
65 | a {} b {}
|
66 | ```
|
67 |
|
68 |
|
69 | ```css
|
70 | a {}
|
71 | b {}
|
72 | ```
|
73 |
|
74 | ### `"always-multi-line"`
|
75 |
|
76 | There _must always_ be an empty line before multi-line rules.
|
77 |
|
78 | The following patterns are considered problems:
|
79 |
|
80 |
|
81 | ```css
|
82 | a {
|
83 | color: red;
|
84 | }
|
85 | b {
|
86 | color: blue;
|
87 | }
|
88 | ```
|
89 |
|
90 | The following patterns are _not_ considered problems:
|
91 |
|
92 |
|
93 | ```css
|
94 | a {
|
95 | color: red;
|
96 | }
|
97 |
|
98 | b {
|
99 | color: blue;
|
100 | }
|
101 | ```
|
102 |
|
103 | ### `"never-multi-line"`
|
104 |
|
105 | There _must never_ be an empty line before multi-line rules.
|
106 |
|
107 | The following patterns are considered problems:
|
108 |
|
109 |
|
110 | ```css
|
111 | a {
|
112 | color: red;
|
113 | }
|
114 |
|
115 | b {
|
116 | color: blue;
|
117 | }
|
118 | ```
|
119 |
|
120 | The following patterns are _not_ considered problems:
|
121 |
|
122 |
|
123 | ```css
|
124 | a {
|
125 | color: red;
|
126 | }
|
127 | b {
|
128 | color: blue;
|
129 | }
|
130 | ```
|
131 |
|
132 | ## Optional secondary options
|
133 |
|
134 | ### `except: ["after-rule", "after-single-line-comment", "inside-block-and-after-rule", "inside-block", "first-nested"]`
|
135 |
|
136 | #### `"after-rule"`
|
137 |
|
138 | Reverse the primary option for rules that follow another rule.
|
139 |
|
140 | For example, with `"always"`:
|
141 |
|
142 | The following patterns are considered problems:
|
143 |
|
144 |
|
145 | ```css
|
146 | a {}
|
147 |
|
148 | b {}
|
149 | ```
|
150 |
|
151 | The following patterns are _not_ considered problems:
|
152 |
|
153 |
|
154 | ```css
|
155 | a {}
|
156 | b {}
|
157 | ```
|
158 |
|
159 | #### `"after-single-line-comment"`
|
160 |
|
161 | Reverse the primary option for rules that follow a single-line comment.
|
162 |
|
163 | For example, with `"always"`:
|
164 |
|
165 | The following patterns are considered problems:
|
166 |
|
167 |
|
168 | ```css
|
169 | /* comment */
|
170 |
|
171 | a {}
|
172 | ```
|
173 |
|
174 | The following patterns are _not_ considered problems:
|
175 |
|
176 |
|
177 | ```css
|
178 | /* comment */
|
179 | a {}
|
180 | ```
|
181 |
|
182 | #### `"inside-block-and-after-rule"`
|
183 |
|
184 | Reverse the primary option for rules that are inside a block and follow another rule.
|
185 |
|
186 | For example, with `"always"`:
|
187 |
|
188 | The following patterns are considered problems:
|
189 |
|
190 |
|
191 | ```css
|
192 | @media {
|
193 |
|
194 | a {}
|
195 |
|
196 | b {}
|
197 | }
|
198 | ```
|
199 |
|
200 | The following patterns are _not_ considered problems:
|
201 |
|
202 |
|
203 | ```css
|
204 | @media {
|
205 |
|
206 | a {}
|
207 | b {}
|
208 | }
|
209 | ```
|
210 |
|
211 | #### `"inside-block"`
|
212 |
|
213 | Reverse the primary option for rules that are inside a block.
|
214 |
|
215 | For example, with `"always"`:
|
216 |
|
217 | The following patterns are considered problems:
|
218 |
|
219 |
|
220 | ```css
|
221 | a {
|
222 | color: red;
|
223 |
|
224 | & b {
|
225 | color: blue;
|
226 | }
|
227 | }
|
228 |
|
229 | ```
|
230 |
|
231 | The following patterns are _not_ considered problems:
|
232 |
|
233 |
|
234 | ```css
|
235 | a {
|
236 | color: red;
|
237 | & b {
|
238 | color: blue;
|
239 | }
|
240 | }
|
241 | ```
|
242 |
|
243 | #### `"first-nested"`
|
244 |
|
245 | Reverse the primary option for rules that are nested and the first child of their parent node.
|
246 |
|
247 | For example, with `"always"`:
|
248 |
|
249 | The following patterns are considered problems:
|
250 |
|
251 |
|
252 | ```css
|
253 | @media {
|
254 |
|
255 | a {}
|
256 |
|
257 | b {}
|
258 | }
|
259 | ```
|
260 |
|
261 | The following patterns are _not_ considered problems:
|
262 |
|
263 |
|
264 | ```css
|
265 | @media {
|
266 | a {}
|
267 |
|
268 | b {}
|
269 | }
|
270 | ```
|
271 |
|
272 | ### `ignore: ["after-comment", "first-nested", "inside-block"]`
|
273 |
|
274 | #### `"after-comment"`
|
275 |
|
276 | Ignore rules that follow a comment.
|
277 |
|
278 | For example, with `"always"`:
|
279 |
|
280 | The following patterns are _not_ considered problems:
|
281 |
|
282 |
|
283 | ```css
|
284 | /* comment */
|
285 | a {}
|
286 | ```
|
287 |
|
288 | #### `"first-nested"`
|
289 |
|
290 | Ignore rules that are nested and the first child of their parent node.
|
291 |
|
292 | For example, with `"always"`:
|
293 |
|
294 | The following patterns are _not_ considered problems:
|
295 |
|
296 |
|
297 | ```css
|
298 | @media {
|
299 | a {}
|
300 |
|
301 | b {}
|
302 | }
|
303 | ```
|
304 |
|
305 | #### `"inside-block"`
|
306 |
|
307 | Ignore rules that are inside a block.
|
308 |
|
309 | For example, with `"always"`:
|
310 |
|
311 | The following patterns are _not_ considered problems:
|
312 |
|
313 |
|
314 | ```css
|
315 | @media {
|
316 | a {}
|
317 | }
|
318 | ```
|
319 |
|
320 |
|
321 | ```css
|
322 | @media {
|
323 | a {}
|
324 | b {}
|
325 | }
|
326 | ```
|