为什么某些次要选项不适用于我的 .stylelintrc 中的规则?

Why are some of the secondary options not working for the rules in my .stylelintrc?

我正在尝试格式化我的 css 以便行与行之间不超过一个空行,但我不希望它应用于评论。 stylelint 的文档有一个辅助选项,应该可以使这变得容易,但由于某种原因它不起作用。规则如下:

"max-empty-lines": [
      1,
      {
        "ignore": [
          "comments"
        ]
      }
    ],

这是我的 .stylelintrc 的其余部分以供参考:

{
  "rules": {
    "at-rule-empty-line-before": "always",
    "at-rule-no-unknown": true,
    "block-closing-brace-empty-line-before": "never",
    "block-closing-brace-newline-before": "always",
    "block-opening-brace-newline-after": "always",
    "block-opening-brace-space-before": "always",
    "block-no-empty": null,
    "color-no-invalid-hex": true,
    "color-hex-case": "upper",
    "color-hex-length": "short",
    "comment-empty-line-before": [
      "always",
      {
        "except": [
          "first-nested"
        ]
      }
    ],
    "comment-no-empty": true,
    "comment-whitespace-inside": "never",
    "custom-property-empty-line-before": "never",
    "custom-property-no-missing-var-function": true,
    "declaration-block-no-duplicate-custom-properties": true,
    "declaration-block-no-duplicate-properties": [
      true,
      {
        "ignore": [
          "consecutive-duplicates-with-different-values"
        ]
      }
    ],
    "declaration-block-no-shorthand-property-overrides": true,
    "declaration-block-semicolon-newline-after": "always",
    "declaration-block-semicolon-newline-before": "never-multi-line",
    "declaration-block-semicolon-space-before": "never",
    "declaration-block-semicolon-space-after": "never-single-line",
    "declaration-block-trailing-semicolon": "always",
    "declaration-colon-space-before": "never",
    "declaration-colon-space-after": "always",
    "declaration-empty-line-before": "never",
    "font-family-no-duplicate-names": true,
    "font-family-no-missing-generic-family-keyword": true,
    "function-calc-no-unspaced-operator": true,
    "function-linear-gradient-no-nonstandard-direction": true,
    "function-no-unknown": true,
    "keyframe-declaration-no-important": true,
    "max-empty-lines": [
      1,
      {
        "ignore": [
          "comments"
        ]
      }
    ],
    "media-feature-name-no-unknown": true,
    "named-grid-areas-no-invalid": true,
    "no-descending-specificity": true,
    "no-duplicate-at-import-rules": true,
    "no-duplicate-selectors": true,
    "no-empty-source": true,
    "no-eol-whitespace": true,
    "no-extra-semicolons": true,
    "no-invalid-double-slash-comments": true,
    "no-invalid-position-at-import-rule": true,
    "no-irregular-whitespace": true,
    "property-no-unknown": true,
    "rule-empty-line-before": "always",
    "selector-list-comma-newline-after": "always",
    "selector-list-comma-newline-before": "never-multi-line",
    "selector-list-comma-space-before": "never",
    "selector-max-empty-lines": 0,
    "selector-pseudo-class-no-unknown": true,
    "selector-pseudo-element-no-unknown": true,
    "selector-type-no-unknown": [
      true,
      {
        "ignore": [
          "custom-elements"
        ]
      }
    ],
    "string-no-newline": true,
    "unit-no-unknown": true
  }
}

您正确使用了次要选项 this demo shows:

{
  "rules": {
    "max-empty-lines": [1, {"ignore": ["comments"]}]
  }
}
/* comment 


*/

a {}


b {}

第 8 行仅给出一个错误:

8:1 error Expected no more than 1 empty line (max-empty-lines)

如果您在本地没有看到这种行为,我建议 reporting a bug 在 Stylelint 问题跟踪器中。