Vize

script/no-deep-destructure-in-props

禁止在 defineProps 中进行深层嵌套解构。

默认严重程度 预设 自动修复 选项
warning opinionated, nuxt 不支持 无

适用范围:Vue SFC 中的 JS/TS 脚本;示例展示对应的 Options API 或 script setup 形式。

错误示例

绑定模式进入 user 解构 name,超过默认的浅层 props 解构深度。

<script setup lang="ts">
const { user: { name } } = defineProps<{ user: { name: string } }>();
</script>

正确示例

props 对象保持完整,由计算 getter 读取 props.user.name。嵌套访问保持显式,不使用深层嵌套绑定模式。

<script setup lang="ts">
import { computed } from "vue";
const props = defineProps<{ user: { name: string } }>();
const userName = computed(() => props.user.name);
</script>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "script/no-deep-destructure-in-props": "warn"
    }
  },
});

然后运行 vp run lint。

相关页面