|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- # comment-empty-line-before
-
- Require or disallow an empty line before comments.
-
- <!-- prettier-ignore -->
- ```css
- a {}
- /* ← */
- /* comment */ /* ↑ */
- /** ↑
- * This line */
- ```
-
- This rule ignores:
-
- - comments that are the very first node in the source
- - shared-line comments
- - single-line comments with `//` (when you're using a custom syntax that supports them)
- - comments within selector and value lists
-
- 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.
-
- ## Options
-
- `string`: `"always"|"never"`
-
- ### `"always"`
-
- There _must always_ be an empty line before comments.
-
- The following patterns are considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {}
- /* comment */
- ```
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {}
-
- /* comment */
- ```
-
- <!-- prettier-ignore -->
- ```css
- a {} /* comment */
- ```
-
- ### `"never"`
-
- There _must never_ be an empty line before comments.
-
- The following patterns are considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {}
-
- /* comment */
- ```
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {}
- /* comment */
- ```
-
- <!-- prettier-ignore -->
- ```css
- a {} /* comment */
- ```
-
- ## Optional secondary options
-
- ### `except: ["first-nested"]`
-
- Reverse the primary option for comments that are nested and the first child of their parent node.
-
- For example, with `"always"`:
-
- The following patterns are considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
-
- /* comment */
- color: pink;
- }
- ```
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- /* comment */
- color: pink;
- }
- ```
-
- ### `ignore: ["after-comment", "stylelint-commands"]`
-
- #### `"after-comment"`
-
- Ignore comments that follow another comment.
-
- For example, with `"always"`:
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- background: pink;
-
- /* comment */
- /* comment */
- color: #eee;
- }
- ```
-
- <!-- prettier-ignore -->
- ```css
- a {
- background: pink;
-
- /* comment */
-
- /* comment */
- color: #eee;
- }
- ```
-
- #### `"stylelint-commands"`
-
- Ignore comments that deliver commands to stylelint, e.g. `/* stylelint-disable color-no-hex */`.
-
- For example, with `"always"`:
-
- The following patterns are considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- background: pink;
- /* not a stylelint command */
- color: #eee;
- }
- ```
-
- The following patterns are _not_ considered violations:
-
- <!-- prettier-ignore -->
- ```css
- a {
- background: pink;
- /* stylelint-disable color-no-hex */
- color: pink;
- }
- ```
-
- ### `ignoreComments: ["/regex/", /regex/, "string"]`
-
- Ignore comments matching the given regular expressions or strings.
-
- For example, with `"always"` and given:
-
- ```
- [/^ignore/, "string-ignore"]
- ```
-
- The following comments are _not_ considered violations:
-
- ```css
- :root {
- background: pink;
- /* ignore this comment because of the regex */
- color: pink;
- }
- ```
-
- ```css
- :root {
- background: pink;
- /* string-ignore */
- color: pink;
- }
- ```
|