script/no-unstable-nested-components
setup / render 内で毎回コンポーネントを定義する箇所を検出します。
| 既定の重大度 | プリセット | 自動修正 | オプション |
|---|---|---|---|
warning |
happy-path, ecosystem, nuxt, opinionated |
なし | なし |
適用範囲:Vue SFC の JavaScript / TypeScript の script ブロック。対象となる Options API または script setup の形式は例を参照してください。
悪い例
親の setup() 内で defineComponent を呼び、setup が実行されるたびに新しい Child のコンポーネント定義を作っています。
<script lang="ts">
import { defineComponent } from "vue";
export default { setup() { const Child = defineComponent({ render() { return null; } }); return { Child }; } };
</script>
良い例
Child の定義をモジュール直下に移し、setup() は作り直さず既存の定義を返すようにします。
<script lang="ts">
import { defineComponent } from "vue";
const Child = defineComponent({ render() { return null; } });
export default { setup() { return { Child }; } };
</script>
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/no-unstable-nested-components": "warn"
}
},
});
設定したら vp run lint を実行します。