Vize

script/no-reserved-identifiers

禁止使用 Vue 编译器保留标识符。

默认严重程度 预设 自动修复 选项
error essential, happy-path, ecosystem, nuxt, opinionated 不支持 无

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

错误示例

绑定 __props、__emit 和 __sfc__ 使用了为 Vue 编译器生成代码保留的标识符。

<script setup lang="ts">
const __props = { name: "Ada" };
const __emit = () => {};
const __sfc__ = {};
</script>

正确示例

普通名称 props、emit 和 componentData 避开这些生成标识符,同时保留 props 和 emits 声明。

<script setup lang="ts">
const props = defineProps<{ name: string }>();
const emit = defineEmits<{ save: [] }>();
const componentData = {};
</script>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "script/no-reserved-identifiers": "error"
    }
  },
});

然后运行 vp run lint。

相关页面