vue/return-in-emits-validator Correctness
作用
强制在 emits 验证器中存在 return 语句 (适用于 Vue.js 3.0.0+)。
为什么这不好?
emits 验证器必须返回一个布尔值,表示 发出的负载是否有效。忘记返回值(或只返回 假值)会使验证器实际上拒绝每一次 emit, 从而静默地破坏组件契约。
示例
以下是此规则的错误代码示例:
vue
<script>
export default {
emits: {
foo() {
// 缺少 return
},
},
};
</script>以下是此规则的正确代码示例:
vue
<script>
export default {
emits: {
foo(payload) {
return typeof payload === "string";
},
},
};
</script>如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/return-in-emits-validator": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/return-in-emits-validator": "error",
},
});bash
oxlint --deny vue/return-in-emits-validator --vue-plugin版本
此规则于 v1.67.0 中添加。
