Skip to content

quoted-strings

GitHub ActionsYAMLstylefix: unsafedefault: off

Reports strings that are quoted or unquoted against the rule you set with required: always wants quotes on every string, only_when_needed reports quotes that change nothing (unless extra_allowed matches) and plain strings that extra_required matches, optional only the latter. quote_type sets the quotes. Plain scalars that are not strings (12, true, null, dates, …), block scalars and scalars tagged !! are never checked.

Whether to quote is a style choice, but it matters for safety: an unquoted no, 1e3 or 0755 is not the string it looks like. A project that always quotes strings never has to know which words YAML reads as something else, and one that never quotes unless needed keeps the files short.

Fixes quote a plain string and change the quote type, both keep the value. Removing quotes is unsafe, since a YAML 1.2 parser reads some strings (1e3) as numbers.

Reported
name: bar
quoted: "baz"
num: 1
After the fix
name: "bar"
quoted: "baz"
num: 1
github-actions:
lint:
rules:
quoted-strings:
level: warn # off (default), warn, error
options:
quote_type: "any"
required: "always"
extra_required: []
extra_allowed: []
allow_quoted_quotes: false
check_keys: false
yaml:
lint:
rules:
quoted-strings:
level: warn # off (default), warn, error
options:
quote_type: "any"
required: "always"
extra_required: []
extra_allowed: []
allow_quoted_quotes: false
check_keys: false
Option Type Default Description
quote_type string "any" The quotes to use. consistent: the first quoted string of the file decides.
Values: any, single, double, consistent
required string "always" always: every string is quoted. optional: quotes are free, but must be of quote_type. only_when_needed: quotes only where the string would otherwise read as something else.
Values: always, optional, only_when_needed
extra_required list [] Regular expressions; a string they match (searched in the value) must be quoted even with optional or only_when_needed.
extra_allowed list [] Regular expressions; a string they match may be quoted with only_when_needed.
allow_quoted_quotes bool false Accept the other quote type when the string contains the wanted quote.
check_keys bool false Check mapping keys too.

Suppress one line with sudsy-disable-next-line quoted-strings in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
yamllint quoted-strings full
yamllint quoted-strings.quote-type full
yamllint quoted-strings.required full
yamllint quoted-strings.extra-required / extra-allowed full
yamllint quoted-strings.allow-quoted-quotes full
yamllint quoted-strings.check-keys full