Skip to content

noVueRestrictedComponentOptions (JavaScript)

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

Disallow configured options in Vue components.

A Vue component is described by an object of options, such as props, data or mounted. Some projects want to avoid certain options, for example options that a library no longer supports, or options the team decided to stop using.

This rule reports the options listed in the componentOptions option. It checks the object passed to defineComponent() or createApp(), the object exported by default from the <script> block of a .vue file, and the object passed to defineOptions() in <script setup>. It does nothing until you list at least one option.

The examples below use the following configuration:

biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueRestrictedComponentOptions": {
"level": "on",
"options": {
"componentOptions": [
"init",
[
"props",
"*",
"twoWay"
]
]
}
}
}
}
}
}
<script>
export default {
init() {},
};
</script>
code-block.vue:3:3 lint/nursery/noVueRestrictedComponentOptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The component option init is not allowed.

1 │ <script>
2 │ export default {
> 3 │ init() {},
│ ^^^^
4 │ };
5 │ </script>

ℹ Your project lists this component option under componentOptions in the configuration of this rule, so it isn't allowed.

ℹ Remove this option, or replace it with the alternative your project recommends.

ℹ 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>
export default {
props: {
name: { type: String, twoWay: true },
},
};
</script>
code-block.vue:4:27 lint/nursery/noVueRestrictedComponentOptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The component option props.*.twoWay is not allowed.

2 │ export default {
3 │ props: {
> 4 │ name: { type: String, twoWay: true },
│ ^^^^^^
5 │ },
6 │ };

ℹ Your project lists this component option under componentOptions in the configuration of this rule, so it isn't allowed.

ℹ Remove this option, or replace it with the alternative your project recommends.

ℹ 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>
defineOptions({
init() {},
});
</script>
code-block.vue:3:3 lint/nursery/noVueRestrictedComponentOptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ The component option init is not allowed.

1 │ <script setup>
2 │ defineOptions({
> 3 │ init() {},
│ ^^^^
4 │ });
5 │ </script>

ℹ Your project lists this component option under componentOptions in the configuration of this rule, so it isn't allowed.

ℹ Remove this option, or replace it with the alternative your project recommends.

ℹ 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>
export default {
beforeCreate() {},
props: {
name: { type: String, required: true },
},
};
</script>

Default: []

The component options that must not be used. Each entry is one of the following:

  • The name of an option, such as "init".
  • A list of names that leads to an option inside other options. For example, ["props", "name", "twoWay"] matches twoWay in props: { name: { twoWay: true } }. The name "*" matches any property, including spread properties such as ...other and properties whose name is computed, such as [key].
  • An object with these properties:
    • name: The name of the option, or a list of names as described above. This property is required.
    • message: A custom message to show in place of the default message.

Names must match the property names exactly.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueRestrictedComponentOptions": {
"level": "on",
"options": {
"componentOptions": [
{
"name": "init",
"message": "Use beforeCreate() instead."
},
{
"name": [
"props",
"*",
"twoWay"
],
"message": "Two-way props are not supported."
}
]
}
}
}
}
}
}
<script>
export default {
init() {},
};
</script>
code-block.vue:3:3 lint/nursery/noVueRestrictedComponentOptions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ Use beforeCreate() instead.

1 │ <script>
2 │ export default {
> 3 │ init() {},
│ ^^^^
4 │ };
5 │ </script>

ℹ Your project lists this component option under componentOptions in the configuration of this rule, so it isn't allowed.

ℹ Remove this option, or replace it with the alternative your project recommends.

ℹ 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>
export default {
beforeCreate() {},
props: {
name: { type: String },
},
};
</script>