useVueMatchingComponentFileName (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
lint/nursery/useVueMatchingComponentFileName - This rule has an unsafe fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Inspired from
vue/match-component-file-name
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueMatchingComponentFileName": "error" } } }}Description
Section titled “Description”Enforce that the name of a Vue component matches its file name.
When a component’s name differs from the name of the file that defines it, finding the component’s source from its name, or the other way around, becomes harder.
The names must be identical, including uppercase and lowercase letters: a component named
my-component doesn’t match the file MyComponent.vue.
The rule checks every component whose name is written as a string, including when a file defines several components. It reads the component’s name from:
- the
nameoption ofexport default { ... }in a.vue,.jsx, or.tsxfile; - the
nameoption passed todefineComponent(),createApp(), ordefineOptions(); - the name passed to
app.component()together with the component’s definition.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<script>export default { name: "MyButton"};</script>/MyComponent.vue:3:9 lint/nursery/useVueMatchingComponentFileName FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The component name "MyButton" doesn't match the file name "MyComponent".
1 │ <script>
2 │ export default {
> 3 │ name: "MyButton"
│ ^^^^^^^^^^
4 │ };
5 │ </script>
ℹ When a component and its file have different names, it's harder to find where the component is defined.
ℹ Rename the component or the file so that both names are the same.
ℹ 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.
ℹ Unsafe fix: Rename the component to "MyComponent".
1 1 │ <script>
2 2 │ export default {
3 │ - ··name:·"MyButton"
3 │ + ··name:·"MyComponent"
4 4 │ };
5 5 │ </script>
<script setup>defineOptions({ name: "my-component"});</script>/MyComponent.vue:3:9 lint/nursery/useVueMatchingComponentFileName FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The component name "my-component" doesn't match the file name "MyComponent".
1 │ <script setup>
2 │ defineOptions({
> 3 │ name: "my-component"
│ ^^^^^^^^^^^^^^
4 │ });
5 │ </script>
ℹ When a component and its file have different names, it's harder to find where the component is defined.
ℹ Rename the component or the file so that both names are the same.
ℹ 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.
ℹ Unsafe fix: Rename the component to "MyComponent".
1 1 │ <script setup>
2 2 │ defineOptions({
3 │ - ··name:·"my-component"
3 │ + ··name:·"MyComponent"
4 4 │ });
5 5 │ </script>
app.component("MyButton", { template: "<div />"});/MyComponent.js:1:15 lint/nursery/useVueMatchingComponentFileName FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The component name "MyButton" doesn't match the file name "MyComponent".
> 1 │ app.component("MyButton", {
│ ^^^^^^^^^^
2 │ template: "<div />"
3 │ });
ℹ When a component and its file have different names, it's harder to find where the component is defined.
ℹ Rename the component or the file so that both names are the same.
ℹ 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.
ℹ Unsafe fix: Rename the component to "MyComponent".
1 │ - app.component("MyButton",·{
1 │ + app.component("MyComponent",·{
2 2 │ template: "<div />"
3 3 │ });
<script>export default { name: "MyComponent"};</script>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.