Vize

vue/enforce-style-attribute

将 style 块限制为允许的属性模式。

默认严重程度 预设 自动修复 选项
warning 无 不支持 规则选项

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

错误示例

module 样式模式不在配置的允许列表中。

<template><div /></template>
<style module>.card { color: red }</style>

正确示例

scoped 样式模式符合项目策略。

<template><div /></template>
<style scoped>.card { color: red }</style>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/enforce-style-attribute": "warn"
    },
    "ruleOptions": {
      "vue/enforce-style-attribute": {
        "allow": [
          "scoped"
        ]
      }
    }
  },
});

然后运行 vp run lint。

相关页面