vue/require-scoped-style
style に scoped を指定する方針を適用します。
| 既定の重大度 | プリセット | 自動修正 | オプション |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
なし | なし |
適用範囲:Vue SFC のテンプレートと各ブロック。ルールに必要な script の文脈も例に含めています。
悪い例
.button の style にスコープがなく、他のコンポーネントの一致する要素にも作用します。
<style>
.button {
color: red;
}
</style>
良い例
scoped を style に付け、同じセレクタと宣言に Vue のコンポーネントスコープを適用します。
<style scoped>
.button {
color: red;
}
</style>
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/require-scoped-style": "warn"
}
},
});
設定したら vp run lint を実行します。