script/consistent-props-emits-key-quotes
统一 props 和 emits 声明中带引号的键。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
error |
无 | 不支持 | 无 |
适用范围:Vue SFC 中的 JS/TS 脚本;示例展示对应的 Options API 或 script setup 形式。
格式化工具兼容性
此 lint 规则负责按声明管理引号。请将 Prettier、Oxfmt 和 Vize 格式化器的 quoteProps 设置为 "preserve",以免格式化时删除规则要求的引号。
错误示例
emits 声明将必须带引号的 update:modelValue 键与不带引号的 close 键混合使用。
<script setup lang="ts">
const emit = defineEmits<{
"update:modelValue": [value: string]
close: []
}>()
</script>
正确示例
声明中的所有静态键都带引号,因为 update:modelValue 无法写成不带引号的 JavaScript 标识符。
<script setup lang="ts">
const emit = defineEmits<{
"update:modelValue": [value: string]
"close": []
}>()
const props = defineProps({
"aria-label": String,
"disabled": Boolean,
})
</script>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/consistent-props-emits-key-quotes": "error"
}
},
});
然后运行 vp run lint。