css/no-important
通常のカスケードを上書きする !important を検出します。
| 既定の重大度 | プリセット | 自動修正 | オプション |
|---|---|---|---|
warning |
opinionated, nuxt |
なし | なし |
適用範囲:プレーン CSS の style ブロック(scss・sass・less・stylus のブロックは対象外)。
悪い例
color に !important を付け、通常のカスケードの優先順位を上書きしています。
<style scoped>
.button {
color: red !important;
}
</style>
良い例
important を使わず、カスタムプロパティから色を参照します。
<style scoped>
.button {
color: var(--button-color);
}
</style>
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"css/no-important": "warn"
}
},
});
設定したら vp run lint を実行します。