跳至主要內容

comment-empty-line-before

在註解前需要或禁止空行。

a {}
/* ← */
/* comment */ /* ↑ */
/** ↑
* This line */

此規則會忽略

  • 原始程式碼中第一個節點的註解
  • 共享行註解
  • 使用 // 的單行註解(當您使用支援它們的自訂語法時)
  • 選擇器和值清單中的註解

fix 選項 可以自動修正此規則報告的所有問題。

選項

字串"always"|"never"

"always"

註解前必須永遠有空行。

以下模式會被視為問題

a {}
/* comment */

以下模式不會被視為問題

a {}

/* comment */
a {} /* comment */

"never"

註解前絕不可以有空行。

以下模式會被視為問題

a {}

/* comment */

以下模式不會被視為問題

a {}
/* comment */
a {} /* comment */

可選的次要選項

except: ["first-nested"]

反轉巢狀且為其父節點第一個子節點的註解的主要選項。

例如,使用 "always"

以下模式會被視為問題

a {

/* comment */
color: pink;
}

以下模式不會被視為問題

a {
/* comment */
color: pink;
}

ignore: ["after-comment", "stylelint-commands"]

"after-comment"

忽略在其他註解後面的註解。

例如,使用 "always"

以下模式不會被視為問題

a {
background: pink;

/* comment */
/* comment */
color: #eee;
}
a {
background: pink;

/* comment */

/* comment */
color: #eee;
}

"stylelint-commands"

忽略設定檔註解,例如 /* stylelint-disable color-no-hex */

例如,使用 "always"

以下模式會被視為問題

a {
background: pink;
/* not a configuration comment */
color: #eee;
}

以下模式不會被視為問題

a {
background: pink;
/* stylelint-disable color-no-hex */
color: pink;
}

ignoreComments: ["/regex/", /regex/, "string"]

忽略與給定正規表示式或字串相符的註解。

例如,使用 "always" 並給定

["/^ignore/", "string-ignore"]

以下模式不會被視為問題

:root {
background: pink;
/* ignore this comment because of the regex */
color: pink;
}
:root {
background: pink;
/* string-ignore */
color: pink;
}