Skip to content

useVueOneComponentPerFile (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useVueOneComponentPerFile": "error"
}
}
}
}

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 .vue file;
  • 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.

<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");