css/prefer-nested-selectors
Recomendar o aninhamento de CSS para seletores de descendentes.
| Severidade padrão | Predefinições | Correção automática | Opções |
|---|---|---|---|
warning |
opinionated, nuxt |
Não | Nenhuma |
Aplicável a: Blocos style em CSS puro (blocos scss, sass, less e stylus são ignorados).
Incorreto
O seletor de descendentes .card .title repete o seletor pai em uma regra sem aninhamento.
<style scoped>
.card .title { color: red; }
</style>
Correto
A regra .title é aninhada dentro de .card, mantendo junta a relação de estilo entre pai e filho.
<style scoped>
.card { .title { color: red; } }
</style>
Configuração (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"css/prefer-nested-selectors": "warn"
}
},
});
Depois, execute vp run lint.