musea/prefer-design-tokens
优先使用设计令牌 CSS 变量,而不是硬编码的原始值。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
无 | 不支持 | 规则选项 |
适用范围:Musea .art.vue 的 art、variant 和 style 块。
需要 .art.vue 文件及下方所示的令牌清单。不会从任意颜色推断设计令牌。
错误示例
art 示例使用蓝色字面量,而不是配置的 primary 设计令牌。
Button.art.vue
<art title="Button" component="Button">
<variant name="Primary"><Button /></variant>
</art>
<style scoped>
.button {
color: #3b82f6;
}
</style>
正确示例
样式引用此示例配置的令牌 --color-primary。
Button.art.vue
<art title="Button" component="Button">
<variant name="Primary"><Button /></variant>
</art>
<style scoped>
.button {
color: var(--color-primary);
}
</style>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"musea/prefer-design-tokens": "warn"
},
"ruleOptions": {
"musea/prefer-design-tokens": {
"tokens": [
{
"path": "color.primary",
"value": "#3b82f6",
"tier": "semantic"
}
]
}
}
},
});
然后运行 vp run lint。