Vize

vue/single-style-block

建议只使用一个 style 块。

默认严重程度 预设 自动修复 选项
warning happy-path, nuxt, ecosystem, opinionated 不支持 无

适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。

错误示例

组件将带作用域的 panel 和 title 样式分散在两个 style 块中。

<style scoped>
.panel {
  color: red;
}
</style>

<style scoped>
.title {
  color: blue;
}
</style>

正确示例

两个选择器都保留在同一个带作用域的 style 块中,满足单块规范,也没有丢弃任何样式。

<style scoped>
.panel {
  color: red;
}
.title {
  color: blue;
}
</style>

配置(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/single-style-block": "warn"
    }
  },
});

然后运行 vp run lint。

相关页面