Skip to content

truthy

What this rule does

Reports bareword string values that YAML 1.1 would interpret as booleans. By default only true and false are accepted; all other YAML 1.1 truthy words (yes, no, on, off, True, Yes, ...) are flagged.

Why this matters

  • Silent type coercion. A literal yes parses as the boolean true under YAML 1.1, which is rarely what an author intended for a country code, a country name, or a configuration value.
  • Cross-parser drift. Some libraries still default to YAML 1.1 semantics, others to 1.2; flagging the ambiguous words makes the document behave the same way everywhere.

Configuration

[lint.rules.truthy]
level = "error"
allowed-values = ["true", "false"]
check-keys = true
Option Default Description
allowed-values ["true", "false"] Bareword values that are permitted. Everything else triggers the rule.
check-keys true Also report truthy values used as mapping keys.

GitHub Actions workflows

A workflow's required on: key is a truthy bareword, so truthy reports it:

$ ryl check .github/workflows/ci.yml
.github/workflows/ci.yml
  2:1       error    truthy value should be one of [false, true]  (truthy)

1 unsafe fix available with `--fix --unsafe-fixes`.

Quoting the key also works: 'on': push passes both truthy and quoted-strings, which keeps quotes needed by YAML 1.1 readers. See YAML version compatibility for how implicit types affect quoting.

Do not apply unsafe fixes with source-version = "1.1" to workflows: on: becomes true:, breaking the workflow. Use the per-file exemption below or a separate nearest config with source-version = "1.2".

Three ways to settle it, narrowest first:

Approach Effect
per-file-ignores on the workflow directory truthy still runs everywhere else. Recommended
check-keys = false No key is checked, in any file
on in allowed-values Also permits on as a value, in any file

The recommended form scopes the exemption to the files that need it:

[lint.rules.truthy]

[lint.per-file-ignores]
".github/workflows/*" = ["truthy"]

Both alternatives apply globally: check-keys = false skips all keys, while allowing on permits on in keys and values. Both still report enabled: yes.

Examples

✅ Allowed (defaults)

enabled: true
visible: false

❌ Reported (defaults)

enabled: yes
flag: On
country: NO
debug: True

🔧 After ryl check --fix (defaults)

enabled: yes
flag: On
country: NO
debug: true

🔧 After ryl check --fix --unsafe-fixes (defaults)

enabled: "yes"
flag: "On"
country: "NO"
debug: true

For files written for a 1.1 reader, choose source-version first.

✅ Allowed (with allowed-values: ["true", "false", "yes", "no"])

enabled: yes
visible: no

YAML version directive

The rule honours an explicit %YAML directive: under %YAML 1.2 the barewords resolve to plain strings, so only true/false spellings are flagged; under %YAML 1.1 the full 1.1 truthy word list is flagged. A document with no directive follows the top-level target-version: the 1.1 list by default, the 1.2 one under target-version = "1.2".

Automatic fixing

For go-yaml consumers (Kubernetes, Helm, Docker Compose), neither source version matches every value; booleans depend on the loader version and destination field. Check the reader and fix ambiguous values by hand before bulk conversion.

ryl check --fix rewrites a flagged case variant of true or false (True, TRUE, False, FALSE) to the first spelling of the same boolean that allowed-values permits, trying lowercase, then title case, then upper case. Every one of those spellings is the same boolean under YAML 1.1 and 1.2, so the value does not change. When allowed-values has no spelling of that boolean, the value is left as it is.

yes, no, on, off and their case variants get an unsafe fix instead, because the right replacement (quote it to keep the string, or change it to a boolean) depends on what the author meant. It applies only in a document with no %YAML directive under the default target-version = "1.1", and follows source-version: enabled: yes becomes enabled: "yes" under "1.2" (the default) and enabled: true under "1.1", taking the first spelling of that boolean allowed-values permits, or none when it permits none.

With check-keys on, keys are fixed too. That can surface a duplicate key: True: 1 and true: 2 in one mapping were always the same boolean key, and key-duplicates reports it once both read true.

  • quoted-strings — quoting a value disables type coercion so the literal stays a string.
  • empty-values — a related class of "what did the author actually mean" ambiguity.