Vize

html/no-dupe-style-properties

禁止内联 style 属性中重复的属性声明。

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

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

错误示例

每个静态 style 都重复了一个属性;margin 和 MARGIN 也算作同一属性。

<template>
  <div style="color: red; color: blue">text</div>
  <div style="margin: 0; MARGIN: 1px">text</div>
</template>

正确示例

静态 style 使用不同的 color 和 background 属性。动态样式绑定不在此静态属性检查范围内。

<template>
  <div style="color: red; background: blue">text</div>
  <div :style="{ color: a, color: b }">text</div>
</template>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "html/no-dupe-style-properties": "warn"
    }
  },
});

然后运行 vp run lint。

相关页面