Skip to content

noYamlBooleanKeys (YAML)

Language YAML
biome.json
{
"linter": {
"rules": {
"nursery": {
"noYamlBooleanKeys": "error"
}
}
}
}

Disallow boolean values as keys in YAML.

YAML reads some unquoted words as boolean values (true or false) instead of text. A key written as one of these words is a boolean, which is rarely intended. Tools that read the file can reject boolean keys, or convert them to text that differs from what is written in the file.

Which words are booleans depends on the YAML version of the document:

  • YAML 1.2, the default: true, True, TRUE, false, False, and FALSE.
  • YAML 1.1: the words above, and also y, Y, yes, Yes, YES, n, N, no, No, NO, on, On, ON, off, Off, and OFF.

A document uses YAML 1.1 when a %YAML 1.1 line comes before its --- line. A document that has no lines starting with % uses the same version as the document before it.

This rule also reports keys marked as booleans with the !!bool tag, and keys that are aliases (such as *flag) to a boolean value.

true: enabled
code-block.yaml:1:1 lint/nursery/noYamlBooleanKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This key is a boolean, not text.

> 1 │ true: enabled
│ ^^^^
2 │

ℹ YAML reads this unquoted word as a boolean value. Tools that read this file can reject boolean keys, or convert them to text that differs from what is written here.

ℹ Wrap the key in quotes to keep it as text.

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

%YAML 1.1
---
no: Norway
code-block.yaml:3:1 lint/nursery/noYamlBooleanKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This key is a boolean, not text.

1 │ %YAML 1.1
2 │ ---
> 3 │ no: Norway
│ ^^
4 │

ℹ YAML reads this unquoted word as a boolean value. Tools that read this file can reject boolean keys, or convert them to text that differs from what is written here.

ℹ Wrap the key in quotes to keep it as text.

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

!!bool "true": enabled
code-block.yaml:1:1 lint/nursery/noYamlBooleanKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This key is tagged as a boolean.

> 1 │ !!bool "true": enabled
│ ^^^^^^
2 │

ℹ Tools that read this file can reject boolean keys, or convert them to text that differs from what is written here.

ℹ Remove the boolean tag and use a text key.

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

default: &flag true
labels: { *flag : enabled }
code-block.yaml:2:11 lint/nursery/noYamlBooleanKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This key is an alias to a boolean value.

1 │ default: &flag true
> 2 │ labels: { *flag : enabled }
│ ^^^^^
3 │

ℹ The alias refers to the value marked with this anchor.

> 1 │ default: &flag true
│ ^^^^^
2 │ labels: { *flag : enabled }
3 │

ℹ Tools that read this file can reject boolean keys, or convert them to text that differs from what is written here.

ℹ Use a text key instead of the alias.

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

"true": enabled
!!str false: disabled
# Without a `%YAML 1.1` line, `no` is text.
no: Norway