Vize

vapor/prefer-static-class

字符串字面量优先使用静态 class,而不是动态 class 绑定。

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

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

错误示例

class 绑定对常量字符串求值,但类名并不会改变。

<template>
  <section :class="'panel panel-primary'">Profile</section>
</template>

正确示例

静态 class 属性表达相同的 panel 类名,无需绑定。

<template>
  <section class="panel panel-primary">Profile</section>
</template>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vapor/prefer-static-class": "warn"
    }
  },
});

然后运行 vp run lint。

相关页面