useVueConsistentBooleanPropStyle (HTML)
Summary
Section titled “Summary”- Rule available since:
v2.6.5 - Diagnostic Category:
lint/nursery/useVueConsistentBooleanPropStyle - This rule has an unsafe fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueConsistentBooleanPropStyle": "error" } } }}Description
Section titled “Description”Enforce a consistent style for component props set to true.
In Vue, a Boolean prop written without a value receives true. This means
<MyComponent disabled /> passes the same value as <MyComponent :disabled="true" />, and
the shorthand form is easier to read.
This rule only checks components. On native HTML elements, an attribute without a value
isn’t always the same as true: for example, <div data-active> sets data-active to an
empty string.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<template> <MyComponent :disabled="true" /></template>code-block.vue:2:16 lint/nursery/useVueConsistentBooleanPropStyle FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The prop disabled has the value true, which can be omitted.
1 │ <template>
> 2 │ <MyComponent :disabled="true" />
│ ^^^^^^^^^^^^^^^^
3 │ </template>
4 │
ℹ A prop written without a value receives true, so the shorthand form is shorter and passes the same value.
ℹ The shorthand form passes true only if the component declares the prop as Boolean and doesn't list String before Boolean. Otherwise, it passes an empty string. Check how the component declares the prop before you remove the value.
ℹ 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: Remove the value.
2 │ ··<MyComponent·:disabled="true"·/>
│ - -------
<template> <MyComponent v-bind:disabled="true" /></template>code-block.vue:2:16 lint/nursery/useVueConsistentBooleanPropStyle FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The prop disabled has the value true, which can be omitted.
1 │ <template>
> 2 │ <MyComponent v-bind:disabled="true" />
│ ^^^^^^^^^^^^^^^^^^^^^^
3 │ </template>
4 │
ℹ A prop written without a value receives true, so the shorthand form is shorter and passes the same value.
ℹ The shorthand form passes true only if the component declares the prop as Boolean and doesn't list String before Boolean. Otherwise, it passes an empty string. Check how the component declares the prop before you remove the value.
ℹ 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: Remove the value.
1 1 │ <template>
2 │ - ··<MyComponent·v-bind:disabled="true"·/>
2 │ + ··<MyComponent·disabled·/>
3 3 │ </template>
4 4 │
<template> <MyComponent disabled /> <MyComponent :disabled="false" /> <MyComponent :disabled="isDisabled" /> <MyComponent disabled="true" /> <input :disabled="true" /></template>Options
Section titled “Options”Default: "shorthand"
How a prop set to true should be written:
"shorthand": write only the name of the prop, such asdisabled."longhand": write the valuetrueexplicitly, such as:disabled="true".
{ "linter": { "rules": { "nursery": { "useVueConsistentBooleanPropStyle": { "level": "on", "options": { "style": "longhand" } } } } }}Invalid
Section titled “Invalid”<template> <MyComponent disabled /></template>code-block.vue:2:16 lint/nursery/useVueConsistentBooleanPropStyle FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The prop disabled is written without a value.
1 │ <template>
> 2 │ <MyComponent disabled />
│ ^^^^^^^^
3 │ </template>
4 │
ℹ This project requires writing the value true explicitly, which makes it clear that the prop receives a boolean.
ℹ A prop without a value receives true only if the component declares it as Boolean and doesn't list String before Boolean. Otherwise, it receives an empty string. Check how the component declares the prop before you add the value.
ℹ 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: Write the value true explicitly.
2 │ ··<MyComponent·:disabled="true"·/>
│ + +++++++
<template> <MyComponent :disabled="true" /> <MyComponent v-bind:disabled="true" /></template>except
Section titled “except”Default: []
A list of prop names that must use the opposite of style. Names must match
exactly, as written in the template. With the default style, the following configuration
requires value to be written in the longhand form:
{ "linter": { "rules": { "nursery": { "useVueConsistentBooleanPropStyle": { "level": "on", "options": { "except": [ "value" ] } } } } }}Invalid
Section titled “Invalid”<template> <MyComponent value /></template>code-block.vue:2:16 lint/nursery/useVueConsistentBooleanPropStyle FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The prop value is written without a value.
1 │ <template>
> 2 │ <MyComponent value />
│ ^^^^^
3 │ </template>
4 │
ℹ This project requires writing the value true explicitly, which makes it clear that the prop receives a boolean.
ℹ A prop without a value receives true only if the component declares it as Boolean and doesn't list String before Boolean. Otherwise, it receives an empty string. Check how the component declares the prop before you add the value.
ℹ 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: Write the value true explicitly.
2 │ ··<MyComponent·:value="true"·/>
│ + +++++++
<template> <MyComponent :value="true" disabled /></template>See Also
Section titled “See Also”- If you want a consistent style for
v-bindin Vue, seeuseVueConsistentVBindStyle. - If you want
Booleanto be listed first in the type of a prop, seeuseVueBooleanPropTypeFirst.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.