noYamlBooleanKeys (YAML)
Language YAML
Summary
Section titled “Summary”- Rule available since:
v2.6.4 - Diagnostic Category:
lint/nursery/noYamlBooleanKeys - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
yml/no-boolean-key
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noYamlBooleanKeys": "error" } } }}Description
Section titled “Description”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, andFALSE. - YAML 1.1: the words above, and also
y,Y,yes,Yes,YES,n,N,no,No,NO,on,On,ON,off,Off, andOFF.
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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”true: enabledcode-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: Norwaycode-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": enabledcode-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 truelabels: { *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: NorwayRelated links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.