css/no-hardcoded-values
CSS に直接記述した値を CSS 変数にまとめます。
| 既定の重大度 | プリセット | 自動修正 | オプション |
|---|---|---|---|
warning |
opinionated, nuxt |
なし | なし |
適用範囲:プレーン CSS の style ブロック(scss・sass・less・stylus のブロックは対象外)。
悪い例
.button のスタイルで、余白の数値と 16 進数の色を宣言に直接指定しています。
<style scoped>
.button {
padding: 12px 16px;
color: #174ea6;
}
</style>
良い例
余白と色を名前付きのカスタムプロパティで参照し、トークンとして管理できる形にします。
<style scoped>
.button {
padding: var(--space-3) var(--space-4);
color: var(--color-action-text);
}
</style>
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"css/no-hardcoded-values": "warn"
}
},
});
設定したら vp run lint を実行します。