useVueOneComponentPerFile (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.5 - Diagnostic Category:
lint/nursery/useVueOneComponentPerFile - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Inspired from
vue/one-component-per-file
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueOneComponentPerFile": "error" } } }}Description
Section titled “Description”Enforce that each file defines at most one Vue component.
When every component lives in its own file, components are easier to find, and each file stays small enough to read and change on its own.
The rule counts every component that a file defines:
- a
<script setup>block; export default { ... }in a.vuefile;defineComponent()called with an options object or a setup function;createApp()called with an options object.
A component that is only imported, as in createApp(App), isn’t counted. The default
export of a plain <script> block that sits next to a <script setup> block is part of the
same component, so it isn’t counted either.
When a file defines more than one component, the rule reports each of them, except the
main component of a .vue file.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<script setup>import { defineComponent, h } from "vue";
const Badge = defineComponent({ render: () => h("span", "New"),});</script>code-block.vue:4:15 lint/nursery/useVueOneComponentPerFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This file defines more than one component.
2 │ import { defineComponent, h } from "vue";
3 │
> 4 │ const Badge = defineComponent({
│ ^^^^^^^^^^^^^^^^^
> 5 │ render: () => h("span", "New"),
> 6 │ });
│ ^^
7 │ </script>
8 │
ℹ Components that share a file are harder to find, and the file grows harder to read and change.
ℹ Move this component to its own file.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<script>import { defineComponent } from "vue";
const TodoItem = defineComponent({ props: ["title"],});
export default { components: { TodoItem },};</script>code-block.vue:4:18 lint/nursery/useVueOneComponentPerFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This file defines more than one component.
2 │ import { defineComponent } from "vue";
3 │
> 4 │ const TodoItem = defineComponent({
│ ^^^^^^^^^^^^^^^^^
> 5 │ props: ["title"],
> 6 │ });
│ ^^
7 │
8 │ export default {
ℹ Components that share a file are harder to find, and the file grows harder to read and change.
ℹ Move this component to its own file.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<script setup>import Badge from "./Badge.vue";</script>import { createApp } from "vue";import App from "./App.vue";
createApp(App).mount("#app");Resources
Section titled “Resources”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.