vue/no-import-compiler-macros Restriction
它的作用
禁止导入 Vue 编译器宏。
为什么这样不好?
以下编译器宏:
definePropsdefineEmitsdefineExposewithDefaultsdefineModeldefineOptionsdefineSlots
在 Vue 3 的 <script setup> 中是全局可用的,不需要显式导入。
示例
以下是此规则的错误代码示例:
vue
<script setup>
import { defineProps, withDefaults } from "vue";
</script>以下是此规则的正确代码示例:
vue
<script setup>
import { ref } from "vue";
</script>如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/no-import-compiler-macros": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/no-import-compiler-macros": "error",
},
});bash
oxlint --deny vue/no-import-compiler-macros --vue-plugin版本
此规则新增于 v1.21.0。
