テンプレートのルールのオプション
これらのオプションは eslint-plugin-vue と同じ名前と既定値を
使います。オプションだけではルールは有効になりません。後から一致する設定はそのルールの
オプション全体を置き換え、{} で既定値に戻します。未定義のフィールドや型の合わない値は拒否します。
vue/no-duplicate-attributes
allowCoexistClass と allowCoexistStyle はどちらも既定で true です。class と :class、
style と :style は同じ要素に並べられます。どちらかを false にすると、2つ目の書き方を
重複として報告します。静的な class 属性が2つある場合は常に重複です。
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
rules: { "vue/no-duplicate-attributes": "error" },
ruleOptions: { "vue/no-duplicate-attributes": { allowCoexistClass: false } },
},
});
この設定で報告される例:
<template>
<div class="card" :class="{ active }" />
</template>
この設定に沿った例:
<template>
<div :class="['card', { active }]" />
</template>
vue/no-multiple-template-root
disallowComments の既定は false です。true にすると、テンプレートのルートに直接置かれ、
どのルート要素にも含まれないコメントも報告します。ルート要素の中のコメントは許可されます。
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
rules: { "vue/no-multiple-template-root": "error" },
ruleOptions: { "vue/no-multiple-template-root": { disallowComments: true } },
},
});
この設定で報告される例:
<template>
<!-- The card -->
<div class="card" />
</template>
この設定に沿った例:
<template>
<div class="card">
<!-- The card -->
</div>
</template>
vue/no-lone-template
ignoreAccessible の既定は false です。true にすると、id か ref を持つ入れ子の
<template> は報告しません。静的な属性と、静的な引数でバインドした属性が対象です。
コードから参照できるためです。
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
rules: { "vue/no-lone-template": "warn" },
ruleOptions: { "vue/no-lone-template": { ignoreAccessible: true } },
},
});
この設定で報告される例:
<template>
<div>
<template><span>Row</span></template>
</div>
</template>
この設定に沿った例:
<template>
<div>
<template ref="row"><span>Row</span></template>
</div>
</template>
vue/no-static-inline-styles
allowBinding の既定は false で、静的な style 属性に加えて :style バインディング内の
静的な値も報告します。true にすると、style 属性だけを報告します。
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
rules: { "vue/no-static-inline-styles": "warn" },
ruleOptions: { "vue/no-static-inline-styles": { allowBinding: true } },
},
});
この設定で報告される例:
<template>
<div style="color: red" />
</template>
この設定に沿った例:
<template>
<div :style="{ color: 'red' }" />
</template>
vue/no-unused-components
ignoreWhenBindingPresent の既定は true です。<component :is="current"> のように is を
文字列リテラル以外にバインドするテンプレートは、登録済みのどのコンポーネントも描画できるため、
そのファイルでは何も報告しません。false にすると、そのバインディングがない場合と同じように登録を
検査します。HTML の修復でパースできなかったテンプレートは、引き続きすべての登録を使う可能性がある
ものとして扱います。
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
rules: { "vue/no-unused-components": "warn" },
ruleOptions: { "vue/no-unused-components": { ignoreWhenBindingPresent: false } },
},
});
この設定で報告される例:
<script>
import Card from "./Card.vue";
import Panel from "./Panel.vue";
export default { components: { Card, Panel }, data: () => ({ current: "Card" }) };
</script>
<template>
<component :is="current" />
</template>
この設定に沿った例:
<script>
import Card from "./Card.vue";
export default { components: { Card } };
</script>
<template>
<Card />
</template>
vue/no-v-html
ignorePattern に既定値はありません。式が正規表現に一致する v-html は報告しません。
識別子はその名前で、それ以外の式は外側の括弧を除いたソースの文字列で照合します。パターンは
Rust の正規表現の構文で、upstream が付ける u フラグと同じく Unicode に対応します。空の
パターンとコンパイルできないパターンは何も除外しません。対象は v-html だけで、innerHTML と
outerHTML のバインディングは引き続き報告します。
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
rules: { "vue/no-v-html": "warn" },
ruleOptions: { "vue/no-v-html": { ignorePattern: "^sanitized" } },
},
});
この設定で報告される例:
<template>
<div v-html="article.body" />
</template>
この設定に沿った例:
<template>
<div v-html="sanitizedBody" />
</template>
Tailwind CSS(linter.tailwind)
ecosystem/tailwind-* のルールは、テンプレートにあるすべてのクラスリストを読みます。対象は class、:class の文字列・テンプレートリテラル・オブジェクトのキー・配列の要素、そして任意の v-bind 式の中にあるクラス用ヘルパー呼び出しの文字列引数です。linter.tailwind には、これらのルールが共有する設定を書きます。
| 設定 | 既定 | 意味 |
|---|---|---|
entry |
なし | Tailwind v4 の CSS エントリー(@import "tailwindcss" を書いたファイル)です。相対パスは、lint するファイルのディレクトリから上にたどって探します。ファイルの glob からエントリーへのマップを書くと、モノレポのアプリごとに別のエントリーを使えます。最初に一致した glob が使われます。 |
callees |
cc、clb、clsx、cn、cnb、ctl、cva、cx、dcnb、objstr、tv、twJoin、twMerge |
引数がクラスリストになるヘルパー関数です。指定したリストが組み込みの名前を置き換えます。 |
未知のクラス・衝突・非推奨・正規の書き方・クラスの順序のルールは、プロジェクトの tailwindcss と @tailwindcss/node(@tailwindcss/vite、@tailwindcss/postcss、@tailwindcss/cli と一緒に入ります)を通して、エントリーに対応する Tailwind 自身のデザインシステムに問い合わせます。テーマの値、@utility、@custom-variant、プラグインもすべて反映され、クラスの順序は prettier-plugin-tailwindcss や oxfmt と同じです。Vize は実行ごとに Node.js を 1 回だけ起動し(PATH 上の node の代わりに VIZE_NODE を指定できます)、エントリーは 1 回だけ読み込み、各クラスは 1 回だけ問い合わせます。正規の書き方には Tailwind 4.1.15 以降が必要で、Tailwind はその表をエントリーごとに 1 回だけ作ります(約 2 秒)。entry を設定しないと、これらのルールは何もチェックしません。Tailwind を読み込めないとき(エントリーのファイルがない、Tailwind が入っていない、Tailwind v3 のとき)は、最初に該当したファイルに通知を 1 回だけ出し、これらのルールはチェックを行いません。空白・重複・折り返しのルールは Tailwind を必要とせず、そのまま動きます。
ecosystem/tailwind-enforce-consistent-line-wrapping は { printWidth?: number; classesPerLine?: number } を受け付けます(既定は 80 で、1 行あたりのクラス数の上限はありません)。静的な class の値だけを折り返します。フォーマッターがクラスの値を書き換えないプロジェクト向けです。
ecosystem/tailwind-no-unknown-classes は { ignore: string[] } も受け付けます。ほかの CSS が定義するクラスを正規表現で指定します。コンポーネント自身の <style> が選択しているクラスと、group・peer のマーカーは報告しません。
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
rules: {
"ecosystem/tailwind-no-unknown-classes": "warn",
"ecosystem/tailwind-no-conflicting-classes": "warn",
},
tailwind: {
entry: { "apps/web/**": "apps/web/src/app.css", "apps/admin/**": "apps/admin/src/main.css" },
callees: ["cn", "cva"],
},
ruleOptions: {
"ecosystem/tailwind-no-unknown-classes": { ignore: ["^js-"] },
},
},
});
Oxlint では、同じオブジェクトを settings.vize.tailwind に書きます。