You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置Stylelint(SCSS):移除首个嵌套选择器前的空行

Stylelint配置需求:选择器间保留空行,首个嵌套选择器除外

我正尝试配置.stylelintrc.json,要求选择器之间始终保留空行,但首个嵌套选择器除外。

当前执行--fix后的效果

.class {
                 
    .is-active {
        color: red;
    }

    .is-disabled {
        color: grey;
    }
}

.block__container {

    &--grid {
                                
        /* autoprefixer grid: no-autoplace */
        grid-template-rows: 1fr auto auto;
    }

    &--full {

        div {
           ....
        }
    }

    &--wide {

       div {
         ...
       }
    }
}

期望的最终效果

//This is what I want
.class {
    .is-active {
        color: red;
    }

    .is-disabled {
        color: grey;
    }
}

.block__container {
    &--grid {                     
        /* autoprefixer grid: no-autoplace */
        grid-template-rows: 1fr auto auto;
    }

    &--full {
        div {
           ....
        }
    }

    &--wide {
       div {
         ...
       }
    }
}

当前.stylelintrc.json配置

{
  "extends": [ "@wordpress/stylelint-config/scss" ],
  "rules": {
    "string-quotes": "single",
    "scss/at-extend-no-missing-placeholder": true,
    "selector-class-pattern": null,
    "selector-id-pattern": null,
    "declaration-empty-line-before": "never",
    "rule-empty-line-before": [
      "always",
      {
        "except": [
          "after-single-line-comment",
          "first-nested"
        ],
        "ignore": [
          "after-comment",
          "first-nested"
        ]
      }
    ],
    "at-rule-empty-line-before": [
      "always",
      {
        "except": [
          "blockless-after-same-name-blockless",
          "blockless-after-blockless",
          "first-nested"
        ],
        "ignore": [
          "after-comment",
          "first-nested",
          "blockless-after-blockless"
        ],
        "ignoreAtRules": [
          "import"
        ]
      }
    ]
  } 
}

请问需要使用/扩展哪些规则、选项或插件才能达到预期效果?非常感谢!

内容的提问来源于stack exchange,提问作者user3486605

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 21:32:53