script/one-component-per-file
Disallow more than one component definition in a file.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
opinionated, nuxt |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
The file exports Parent and also defines an inline Child component in components.
<script lang="ts">
export default {
name: 'Parent',
components: {
Child: { name: 'Child' }
}
}
</script>
Good
The file defines only Parent.
<script lang="ts">
export default {
name: 'Parent'
}
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/one-component-per-file": "warn"
}
},
});
Then run vp run lint.