Vize

vue/prefer-props-shorthand

Vue 3.4 の同名 prop バインディングの省略形を使います。

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

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

悪い例

ハイフン区切りに対応する camelCase も含め、属性と対応する変数名を式に重複して書いています。

<template>
  <MyComponent :foo="foo" />
  <MyComponent :user-name="userName" />
  <span :style="style" />
  <div :aria-label="ariaLabel" />
</template>

良い例

Vue 3.4 以降の同名の省略形で式を省きます。bar のように別の変数を渡す式は明示します。

<template>
  <MyComponent :foo />
  <MyComponent :user-name />
  <span :style />
  <div :aria-label />
  <MyComponent :foo="bar" />
</template>

設定(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/prefer-props-shorthand": "warn"
    }
  },
});

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

関連ページ