Vize

vue/html-self-closing

要素の種類ごとに自己終了タグの形式を揃えます。

既定の重大度 プリセット 自動修正 オプション
warning nuxt, opinionated あり ルールのオプション

適用範囲:Vue SFC のテンプレートと各ブロック。ルールに必要な script の文脈も例に含めています。

悪い例

空のコンポーネントと通常の div を開始タグと終了タグの組で書いており、設定された自己終了タグの表記に合いません。

<template>
  <section>
    <MyComponent></MyComponent>
    <div></div>
  </section>
</template>

良い例

空のコンポーネントと通常要素は自己終了タグにし、void 要素はスラッシュを付けません。内容がある要素は終了タグを残します。

<template>
  <section>
    <MyComponent />
    <div />
    <img>
    <br>
    <div>content</div>
  </section>
</template>

設定(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/html-self-closing": "warn"
    }
  },
});

設定したら vp run lint を実行します。

関連ページ