vue/no-import-compiler-macros 限制
它的作用
禁止导入 Vue 编译器宏。
为什么这是不好的?
以下编译器宏在 Vue 3 的 <script setup> 中全局可用,无需显式导入:
definePropsdefineEmitsdefineExposewithDefaultsdefineModeldefineOptionsdefineSlots
示例
此规则的错误代码示例:
vue
<script setup>
import { defineProps, withDefaults } from "vue";
</script>此规则的正确代码示例:
vue
<script setup>
import { ref } from "vue";
</script>如何使用
要通过配置文件或 CLI 启用此规则,可以使用:
json
{
"plugins": ["vue"],
"rules": {
"vue/no-import-compiler-macros": "error"
}
}bash
oxlint --deny vue/no-import-compiler-macros --vue-plugin