Skip to content

noVueBooleanDefault (JavaScript)

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

Disallow default values for Boolean props in Vue components.

Vue treats a Boolean prop like an HTML boolean attribute: it is true when present and false when absent. A default value breaks that convention. With default: true, the prop can only be turned off by explicitly binding false, and default: false restates what Vue already does.

This rule checks props declared through the props option, defineProps(), withDefaults(), and destructured defineProps() with default values.

<script>
export default {
props: {
disabled: {
type: Boolean,
default: true,
},
},
};
</script>
code-block.vue:6:16 lint/nursery/noVueBooleanDefault ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This Boolean prop has a default value.

4 │ disabled: {
5 │ type: Boolean,
> 6 │ default: true,
│ ^^^^
7 │ },
8 │ },

ℹ Vue already defaults an absent Boolean prop to false. A default of true means the prop can only be turned off by explicitly passing false.

ℹ Remove the default value. If the prop should be enabled by default, invert its name and meaning instead, for example disabled instead of enabled.

ℹ 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 lang="ts">
withDefaults(defineProps<{ disabled?: boolean }>(), {
disabled: false,
});
</script>
code-block.vue:3:13 lint/nursery/noVueBooleanDefault ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This Boolean prop has a default value.

1 │ <script setup lang="ts">
2 │ withDefaults(defineProps<{ disabled?: boolean }>(), {
> 3 │ disabled: false,
│ ^^^^^
4 │ });
5 │ </script>

ℹ Vue already defaults an absent Boolean prop to false. A default of true means the prop can only be turned off by explicitly passing false.

ℹ Remove the default value. If the prop should be enabled by default, invert its name and meaning instead, for example disabled instead of enabled.

ℹ 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 lang="ts">
const { disabled = false } = defineProps<{ disabled?: boolean }>();
</script>
code-block.vue:2:20 lint/nursery/noVueBooleanDefault ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This Boolean prop has a default value.

1 │ <script setup lang="ts">
> 2 │ const { disabled = false } = defineProps<{ disabled?: boolean }>();
│ ^^^^^
3 │ </script>
4 │

ℹ Vue already defaults an absent Boolean prop to false. A default of true means the prop can only be turned off by explicitly passing false.

ℹ Remove the default value. If the prop should be enabled by default, invert its name and meaning instead, for example disabled instead of enabled.

ℹ 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: {
disabled: Boolean,
size: {
type: Number,
default: 1,
},
},
};
</script>
<script setup lang="ts">
defineProps<{ disabled?: boolean }>();
</script>