script/no-import-compiler-macros
Disallow importing Vue compiler macros that are auto-imported
Default severity: error
Presets: essential, happy-path, ecosystem, nuxt, opinionated
Automatic fix: None; review the suggested change
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"script/no-import-compiler-macros": "error"
}
},
},
});
vp run lint
Bad
The vue import includes defineProps and defineEmits, although these are compiler macros available directly in <script setup>.
<script setup lang="ts">
import { defineProps, defineEmits } from "vue";
const props = defineProps<{ title: string }>();
const emit = defineEmits<{ save: [id: number] }>();
</script>
Good
Removing the macro imports leaves both typed macro calls intact; no runtime import is needed for either declaration.
<script setup lang="ts">
const props = defineProps<{ title: string }>();
const emit = defineEmits<{ save: [id: number] }>();
</script>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.