Skip to content

noVueMultipleObjectsInClass (JavaScript)

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

Disallow more than one object in an array passed to :class.

In Vue, an object in a :class array adds each of its keys as a class when the matching value is truthy. Splitting these conditions over several objects in the same array makes it harder to see which classes depend on which conditions. Put them in a single object instead.

<template>
<div :class="[{ active: isActive }, { disabled: isDisabled }]" />
</template>
code-block.vue:2:16 lint/nursery/noVueMultipleObjectsInClass ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This class array contains more than one object.

1 │ <template>
> 2 │ <div :class="[{ active: isActive }, { disabled: isDisabled }]" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │ </template>
4 │

ℹ Spreading conditional classes over several objects makes it harder to see which classes are applied and when.

ℹ Merge the objects into a single object.

ℹ 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.

<template>
<div v-bind:class="['button', { active: isActive }, { disabled: isDisabled }]" />
</template>
code-block.vue:2:22 lint/nursery/noVueMultipleObjectsInClass ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This class array contains more than one object.

1 │ <template>
> 2 │ <div v-bind:class="['button', { active: isActive }, { disabled: isDisabled }]" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │ </template>
4 │

ℹ Spreading conditional classes over several objects makes it harder to see which classes are applied and when.

ℹ Merge the objects into a single object.

ℹ 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.

<template>
<div :class="[{ active: isActive, disabled: isDisabled }]" />
<div :class="['button', { active: isActive }]" />
<div :class="{ active: isActive, disabled: isDisabled }" />
</template>