css/prefer-nested-selectors
子孫セレクターを CSS のネスト構文でまとめます。
| 既定の重大度 | プリセット | 自動修正 | オプション |
|---|---|---|---|
warning |
opinionated, nuxt |
なし | なし |
適用範囲:プレーン CSS の style ブロック(scss・sass・less・stylus のブロックは対象外)。
悪い例
ルールをネストせず、子孫セレクター .card .title に親のセレクターも含めて指定しています。
<style scoped>
.card .title { color: red; }
</style>
良い例
.title のルールを .card の中にネストし、親子のスタイルの関係を一か所にまとめます。
<style scoped>
.card { .title { color: red; } }
</style>
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"css/prefer-nested-selectors": "warn"
}
},
});
設定したら vp run lint を実行します。