vue/cross-file-attrs-fallthrough
属性を渡す親と、属性を自動継承できず $attrs も使っていない子コンポーネントの関係を検査します。
既定の重大度: warning
適用範囲: 到達可能なプロジェクトの宣言と import したコンポーネント
オプション: crossFile と重大度(off/warn/error)
自動修正: なし
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: { preset: "incremental", crossFile: true,
rules: { "vue/cross-file-attrs-fallthrough": "warn" },
},
},
});
vp run lint
共通のプロジェクト ファイル
以下のファイルは悪い例・良い例で共通です。import する Vue と、例で使う場合は vue-router / Pinia をインストールしてください。バージョン固有の注意がある場合は、その前提に合わせてください。エントリー ファイルでコンポーネントの関係を明確にしています。
main.ts
import { createApp } from "vue";
import Root from "./App.vue";
createApp(Root).mount("#app");
index.html
<div id="app"></div>
<script type="module" src="/main.ts"></script>
悪い
親が class="notice" を fragment の子に渡しますが、属性の自動適用先がなく、子も $attrs を使いません。
App.vue
<script setup lang="ts">
import Child from "./Child.vue";
</script>
<template><Child class="notice" /></template>
Child.vue
<template><main>Content</main><aside>Help</aside></template>
良い
子が <main> に $attrs を binding して適用先を選び、隣の <aside> は別に保ちます。
App.vue
<script setup lang="ts">
import Child from "./Child.vue";
</script>
<template><Child class="notice" /></template>
Child.vue
<template><main v-bind="$attrs">Content</main><aside>Help</aside></template>
良い例のファイルは上で説明した変更を示します。プロジェクトには別の検出が残る場合があります。