UNPKG

2.81 kBMarkdownView Raw
1# comment-empty-line-before
2
3Require or disallow an empty line before comments.
4
5<!-- prettier-ignore -->
6```css
7a {}
8 /* ← */
9/* comment */ /* ↑ */
10/** ↑
11* This line */
12```
13
14This 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
21The [`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
29There _must always_ be an empty line before comments.
30
31The following patterns are considered violations:
32
33<!-- prettier-ignore -->
34```css
35a {}
36/* comment */
37```
38
39The following patterns are _not_ considered violations:
40
41<!-- prettier-ignore -->
42```css
43a {}
44
45/* comment */
46```
47
48<!-- prettier-ignore -->
49```css
50a {} /* comment */
51```
52
53### `"never"`
54
55There _must never_ be an empty line before comments.
56
57The following patterns are considered violations:
58
59<!-- prettier-ignore -->
60```css
61a {}
62
63/* comment */
64```
65
66The following patterns are _not_ considered violations:
67
68<!-- prettier-ignore -->
69```css
70a {}
71/* comment */
72```
73
74<!-- prettier-ignore -->
75```css
76a {} /* comment */
77```
78
79## Optional secondary options
80
81### `except: ["first-nested"]`
82
83Reverse the primary option for comments that are nested and the first child of their parent node.
84
85For example, with `"always"`:
86
87The following patterns are considered violations:
88
89<!-- prettier-ignore -->
90```css
91a {
92
93 /* comment */
94 color: pink;
95}
96```
97
98The following patterns are _not_ considered violations:
99
100<!-- prettier-ignore -->
101```css
102a {
103 /* comment */
104 color: pink;
105}
106```
107
108### `ignore: ["after-comment", "stylelint-commands"]`
109
110#### `"after-comment"`
111
112Ignore comments that follow another comment.
113
114For example, with `"always"`:
115
116The following patterns are _not_ considered violations:
117
118<!-- prettier-ignore -->
119```css
120a {
121 background: pink;
122
123 /* comment */
124 /* comment */
125 color: #eee;
126}
127```
128
129<!-- prettier-ignore -->
130```css
131a {
132 background: pink;
133
134 /* comment */
135
136 /* comment */
137 color: #eee;
138}
139```
140
141#### `"stylelint-commands"`
142
143Ignore comments that deliver commands to stylelint, e.g. `/* stylelint-disable color-no-hex */`.
144
145For example, with `"always"`:
146
147The following patterns are considered violations:
148
149<!-- prettier-ignore -->
150```css
151a {
152 background: pink;
153 /* not a stylelint command */
154 color: #eee;
155}
156```
157
158The following patterns are _not_ considered violations:
159
160<!-- prettier-ignore -->
161```css
162a {
163 background: pink;
164 /* stylelint-disable color-no-hex */
165 color: pink;
166}
167```