Vize

vue/no-inline-style

インラインの style 属性を検出します。

既定の重大度 プリセット 自動修正 オプション
warning nuxt, opinionated なし なし

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

悪い例

静的な style 属性に色の宣言を直接書いています。

<template>
  <div style="color: red">Text</div>
</template>

良い例

固定した色にはクラスを使います。ratio に依存する幅の動的な style は、静的属性の検査の対象外です。

<template>
  <div class="text-red">Text</div>
  <span :class="{ 'text-red': isRed }">Text</span>
  <div :style="{ width: `${ratio}%` }">Text</div>
</template>

設定(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/no-inline-style": "warn"
    }
  },
});

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

関連ページ