css/prefer-nested-selectors
子孫セレクターを CSS nesting でまとめます。
既定の重大度: warning
プリセット: opinionated, nuxt
自動修正: なし。修正内容を確認してください
適用範囲: SFC の style ブロック内の CSS
オプション: ルール固有のオプションはありません。重大度とプリセットは設定できます。
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"css/prefer-nested-selectors": "warn"
}
},
},
});
vp run lint
悪い
平らなルールの .card .title に、親のセレクターを含めて指定しています。
<style scoped>
.card .title { color: red; }
</style>
良い
.card の中に .title を入れ、親子のスタイルを一緒に管理します。
<style scoped>
.card { .title { color: red; } }
</style>
良い例は上記の設定でこのルールの検出を避ける例です。他のルールでは検出される場合があります。