Rules
When linting a document with yamllint, a series of rules (such as
line-length, trailing-spaces, etc.) are checked against.
A configuration file can be used to enable or disable these rules, to set their level (error or warning), but also to tweak their options.
This page describes the rules and their options.
anchors
Use this rule to report duplicated anchors and aliases referencing undeclared anchors.
Options
Set
forbid-undeclared-aliasestotrueto avoid aliases that reference an anchor that hasn’t been declared (either not declared at all, or declared later in the document).Set
forbid-duplicated-anchorstotrueto avoid duplications of a same anchor.Set
forbid-unused-anchorstotrueto avoid anchors being declared but not used anywhere in the YAML document via alias.
Default values (when enabled)
rules:
anchors:
forbid-undeclared-aliases: true
forbid-duplicated-anchors: false
forbid-unused-anchors: false
Examples
With
anchors: {forbid-undeclared-aliases: true}the following code snippet would PASS:
--- - &anchor foo: bar - *anchor
the following code snippet would FAIL:
--- - &anchor foo: bar - *unknown
the following code snippet would FAIL:
--- - &anchor foo: bar - <<: *unknown extra: value
With
anchors: {forbid-duplicated-anchors: true}the following code snippet would PASS:
--- - &anchor1 Foo Bar - &anchor2 [item 1, item 2]
the following code snippet would FAIL:
--- - &anchor Foo Bar - &anchor [item 1, item 2]
With
anchors: {forbid-unused-anchors: true}the following code snippet would PASS:
--- - &anchor foo: bar - *anchor
the following code snippet would FAIL:
--- - &anchor foo: bar - items: - item1 - item2
braces
Use this rule to control the use of flow mappings or number of spaces inside
braces ({ and }).
Options
forbidis used to forbid the use of flow mappings which are denoted by surrounding braces ({and}). Usetrueto forbid the use of flow mappings completely. Usenon-emptyto forbid the use of all flow mappings except for empty ones.min-spaces-insidedefines the minimal number of spaces required inside braces.max-spaces-insidedefines the maximal number of spaces allowed inside braces.min-spaces-inside-emptydefines the minimal number of spaces required inside empty braces.max-spaces-inside-emptydefines the maximal number of spaces allowed inside empty braces.
Default values (when enabled)
rules:
braces:
forbid: false
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
Examples
With
braces: {forbid: true}the following code snippet would PASS:
object: key1: 4 key2: 8
the following code snippet would FAIL:
object: { key1: 4, key2: 8 }
With
braces: {forbid: non-empty}the following code snippet would PASS:
object: {}
the following code snippet would FAIL:
object: { key1: 4, key2: 8 }
With
braces: {min-spaces-inside: 0, max-spaces-inside: 0}the following code snippet would PASS:
object: {key1: 4, key2: 8}
the following code snippet would FAIL:
object: { key1: 4, key2: 8 }
With
braces: {min-spaces-inside: 1, max-spaces-inside: 3}the following code snippet would PASS:
object: { key1: 4, key2: 8 }
the following code snippet would PASS:
object: { key1: 4, key2: 8 }
the following code snippet would FAIL:
object: { key1: 4, key2: 8 }
the following code snippet would FAIL:
object: {key1: 4, key2: 8 }
With
braces: {min-spaces-inside-empty: 0, max-spaces-inside-empty: 0}the following code snippet would PASS:
object: {}
the following code snippet would FAIL:
object: { }
With
braces: {min-spaces-inside-empty: 1, max-spaces-inside-empty: -1}the following code snippet would PASS:
object: { }
the following code snippet would FAIL:
object: {}
brackets
Use this rule to control the use of flow sequences or the number of spaces
inside brackets ([ and ]).
Options
forbidis used to forbid the use of flow sequences which are denoted by surrounding brackets ([and]). Usetrueto forbid the use of flow sequences completely. Usenon-emptyto forbid the use of all flow sequences except for empty ones.min-spaces-insidedefines the minimal number of spaces required inside brackets.max-spaces-insidedefines the maximal number of spaces allowed inside brackets.min-spaces-inside-emptydefines the minimal number of spaces required inside empty brackets.max-spaces-inside-emptydefines the maximal number of spaces allowed inside empty brackets.
Default values (when enabled)
rules:
brackets:
forbid: false
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
Examples
With
brackets: {forbid: true}the following code snippet would PASS:
object: - 1 - 2 - abc
the following code snippet would FAIL:
object: [ 1, 2, abc ]
With
brackets: {forbid: non-empty}the following code snippet would PASS:
object: []
the following code snippet would FAIL:
object: [ 1, 2, abc ]
With
brackets: {min-spaces-inside: 0, max-spaces-inside: 0}the following code snippet would PASS:
object: [1, 2, abc]
the following code snippet would FAIL:
object: [ 1, 2, abc ]
With
brackets: {min-spaces-inside: 1, max-spaces-inside: 3}the following code snippet would PASS:
object: [ 1, 2, abc ]
the following code snippet would PASS:
object: [ 1, 2, abc ]
the following code snippet would FAIL:
object: [ 1, 2, abc ]
the following code snippet would FAIL:
object: [1, 2, abc ]
With
brackets: {min-spaces-inside-empty: 0, max-spaces-inside-empty: 0}the following code snippet would PASS:
object: []
the following code snippet would FAIL:
object: [ ]
With
brackets: {min-spaces-inside-empty: 1, max-spaces-inside-empty: -1}the following code snippet would PASS:
object: [ ]
the following code snippet would FAIL:
object: []
colons
Use this rule to control the number of spaces before and after colons (:).
Options
max-spaces-beforedefines the maximal number of spaces allowed before colons (use-1to disable).max-spaces-afterdefines the maximal number of spaces allowed after colons (use-1to disable).
Default values (when enabled)
rules:
colons:
max-spaces-before: 0
max-spaces-after: 1
Examples
With
colons: {max-spaces-before: 0, max-spaces-after: 1}the following code snippet would PASS:
object: - a - b key: value
With
colons: {max-spaces-before: 1}the following code snippet would PASS:
object : - a - b
the following code snippet would FAIL:
object : - a - b
With
colons: {max-spaces-after: 2}the following code snippet would PASS:
first: 1 second: 2 third: 3
the following code snippet would FAIL:
first: 1 2nd: 2 third: 3
commas
Use this rule to control the number of spaces before and after commas (,).
Options
max-spaces-beforedefines the maximal number of spaces allowed before commas (use-1to disable).min-spaces-afterdefines the minimal number of spaces required after commas.max-spaces-afterdefines the maximal number of spaces allowed after commas (use-1to disable).
Default values (when enabled)
rules:
commas:
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
Examples
With
commas: {max-spaces-before: 0}the following code snippet would PASS:
strange var: [10, 20, 30, {x: 1, y: 2}]
the following code snippet would FAIL:
strange var: [10, 20 , 30, {x: 1, y: 2}]
With
commas: {max-spaces-before: 2}the following code snippet would PASS:
strange var: [10 , 20 , 30, {x: 1 , y: 2}]
With
commas: {max-spaces-before: -1}the following code snippet would PASS:
strange var: [10, 20 , 30 , {x: 1, y: 2}]
With
commas: {min-spaces-after: 1, max-spaces-after: 1}the following code snippet would PASS:
strange var: [10, 20, 30, {x: 1, y: 2}]
the following code snippet would FAIL:
strange var: [10, 20,30, {x: 1, y: 2}]
With
commas: {min-spaces-after: 1, max-spaces-after: 3}the following code snippet would PASS:
strange var: [10, 20, 30, {x: 1, y: 2}]
With
commas: {min-spaces-after: 0, max-spaces-after: 1}the following code snippet would PASS:
strange var: [10, 20,30, {x: 1, y: 2}]
comments
Use this rule to control the position and formatting of comments.
Options
Use
require-starting-spaceto require a space character right after the#. Set totrueto enable,falseto disable.Use
ignore-shebangsto ignore a shebang at the beginning of the file whenrequire-starting-spaceis set.min-spaces-from-contentis used to visually separate inline comments from content. It defines the minimal required number of spaces between a comment and its preceding content.
Default values (when enabled)
rules:
comments:
require-starting-space: true
ignore-shebangs: true
min-spaces-from-content: 2
Examples
With
comments: {require-starting-space: true}the following code snippet would PASS:
# This sentence # is a block comment
the following code snippet would PASS:
############################## ## This is some documentation
the following code snippet would FAIL:
#This sentence #is a block comment
With
comments: {min-spaces-from-content: 2}the following code snippet would PASS:
x = 2 ^ 127 - 1 # Mersenne prime number
the following code snippet would FAIL:
x = 2 ^ 127 - 1 # Mersenne prime number
comments-indentation
Use this rule to force comments to be indented like content.
Examples
With
comments-indentation: {}the following code snippet would PASS:
# Fibonacci [0, 1, 1, 2, 3, 5]
the following code snippet would FAIL:
# Fibonacci [0, 1, 1, 2, 3, 5]
the following code snippet would PASS:
list: - 2 - 3 # - 4 - 5
the following code snippet would FAIL:
list: - 2 - 3 # - 4 - 5
the following code snippet would PASS:
# This is the first object obj1: - item A # - item B # This is the second object obj2: []
the following code snippet would PASS:
# This sentence # is a block comment
the following code snippet would FAIL:
# This sentence # is a block comment
document-end
Use this rule to require or forbid the use of document end marker (...).
Options
Set
presenttotruewhen the document end marker is required, or tofalsewhen it is forbidden.
Default values (when enabled)
rules:
document-end:
present: true
Examples
With
document-end: {present: true}the following code snippet would PASS:
--- this: is: [a, document] ... --- - this - is: another one ...
the following code snippet would FAIL:
--- this: is: [a, document] --- - this - is: another one ...
With
document-end: {present: false}the following code snippet would PASS:
--- this: is: [a, document] --- - this - is: another one
the following code snippet would FAIL:
--- this: is: [a, document] ... --- - this - is: another one
document-start
Use this rule to require or forbid the use of document start marker (---).
Options
Set
presenttotruewhen the document start marker is required, or tofalsewhen it is forbidden.
Default values (when enabled)
rules:
document-start:
present: true
Examples
With
document-start: {present: true}the following code snippet would PASS:
--- this: is: [a, document] --- - this - is: another one
the following code snippet would FAIL:
this: is: [a, document] --- - this - is: another one
With
document-start: {present: false}the following code snippet would PASS:
this: is: [a, document] ...
the following code snippet would FAIL:
--- this: is: [a, document] ...
empty-lines
Use this rule to set a maximal number of allowed consecutive blank lines.
Options
maxdefines the maximal number of empty lines allowed in the document.max-startdefines the maximal number of empty lines allowed at the beginning of the file. This option takes precedence overmax.max-enddefines the maximal number of empty lines allowed at the end of the file. This option takes precedence overmax.
Default values (when enabled)
rules:
empty-lines:
max: 2
max-start: 0
max-end: 0
Examples
With
empty-lines: {max: 1}the following code snippet would PASS:
- foo: - 1 - 2 - bar: [3, 4]
the following code snippet would FAIL:
- foo: - 1 - 2 - bar: [3, 4]
empty-values
Use this rule to prevent nodes with empty content, that implicitly result in
null values.
Options
Use
forbid-in-block-mappingsto prevent empty values in block mappings.Use
forbid-in-flow-mappingsto prevent empty values in flow mappings.Use
forbid-in-block-sequencesto prevent empty values in block sequences.
Default values (when enabled)
rules:
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
forbid-in-block-sequences: true
Examples
With
empty-values: {forbid-in-block-mappings: true}the following code snippets would PASS:
some-mapping: sub-element: correctly indented
explicitly-null: null
the following code snippets would FAIL:
some-mapping: sub-element: incorrectly indented
implicitly-null:
With
empty-values: {forbid-in-flow-mappings: true}the following code snippet would PASS:
{prop: null} {a: 1, b: 2, c: 3}
the following code snippets would FAIL:
{prop: }
{a: 1, b:, c: 3}
With
empty-values: {forbid-in-block-sequences: true}the following code snippet would PASS:
some-sequence: - string item
some-sequence: - null
the following code snippets would FAIL:
some-sequence: -
some-sequence: - string item -
float-values
Use this rule to limit the permitted values for floating-point numbers. YAML permits three classes of float expressions: approximation to real numbers, positive and negative infinity and “not a number”.
Options
Use
require-numeral-before-decimalto require floats to start with a numeral (ex0.0instead of.0).Use
forbid-scientific-notationto forbid scientific notation.Use
forbid-nanto forbid NaN (not a number) values.Use
forbid-infto forbid infinite values.
Default values (when enabled)
rules:
float-values:
forbid-inf: false
forbid-nan: false
forbid-scientific-notation: false
require-numeral-before-decimal: false
Examples
With
float-values: {require-numeral-before-decimal: true}the following code snippets would PASS:
anemometer: angle: 0.0
the following code snippets would FAIL:
anemometer: angle: .0
With
float-values: {forbid-scientific-notation: true}the following code snippets would PASS:
anemometer: angle: 0.00001
the following code snippets would FAIL:
anemometer: angle: 10e-6
With
float-values: {forbid-nan: true}the following code snippets would FAIL:
anemometer: angle: .NaN
With
float-values: {forbid-inf: true}the following code snippets would FAIL:
anemometer: angle: .inf
hyphens
Use this rule to control the number of spaces after hyphens (-).
Options
max-spaces-afterdefines the maximal number of spaces allowed after hyphens.
Default values (when enabled)
rules:
hyphens:
max-spaces-after: 1
Examples
With
hyphens: {max-spaces-after: 1}the following code snippet would PASS:
- first list: - a - b - - 1 - 2 - 3
the following code snippet would FAIL:
- first list: - a - b
the following code snippet would FAIL:
- - 1 - 2 - 3
With
hyphens: {max-spaces-after: 3}the following code snippet would PASS:
- key - key2 - key42
the following code snippet would FAIL:
- key - key2 - key42
indentation
Use this rule to control the indentation.
Options
spacesdefines the indentation width, in spaces. Set either to an integer (e.g.2or4, representing the number of spaces in an indentation level) or toconsistentto allow any number, as long as it remains the same within the file.indent-sequencesdefines whether block sequences should be indented or not (when in a mapping, this indentation is not mandatory – some people perceive the-as part of the indentation). Possible values:true,false,whateverandconsistent.consistentrequires either all block sequences to be indented, or none to be.whatevermeans either indenting or not indenting individual block sequences is OK.check-multi-line-stringsdefines whether to lint indentation in multi-line strings. Set totrueto enable,falseto disable.
Default values (when enabled)
rules:
indentation:
spaces: consistent
indent-sequences: true
check-multi-line-strings: false
Examples
With
indentation: {spaces: 1}the following code snippet would PASS:
history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle
With
indentation: {spaces: 4}the following code snippet would PASS:
history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle
the following code snippet would FAIL:
history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle
With
indentation: {spaces: consistent}the following code snippet would PASS:
history: - name: Unix date: 1969 - name: Linux date: 1991 nest: recurse: - haystack: needle
the following code snippet would FAIL:
some: Russian: dolls
With
indentation: {spaces: 2, indent-sequences: false}the following code snippet would PASS:
list: - flying - spaghetti - monster
the following code snippet would FAIL:
list: - flying - spaghetti - monster
With
indentation: {spaces: 2, indent-sequences: whatever}the following code snippet would PASS:
list: - flying: - spaghetti - monster - not flying: - spaghetti - sauce
With
indentation: {spaces: 2, indent-sequences: consistent}the following code snippet would PASS:
- flying: - spaghetti - monster - not flying: - spaghetti - sauce
the following code snippet would FAIL:
- flying: - spaghetti - monster - not flying: - spaghetti - sauce
With
indentation: {spaces: 4, check-multi-line-strings: true}the following code snippet would PASS:
Blaise Pascal: Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte.
the following code snippet would PASS:
Blaise Pascal: Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte.
the following code snippet would FAIL:
Blaise Pascal: Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte.
the following code snippet would FAIL:
C code: void main() { printf("foo"); }
the following code snippet would PASS:
C code: void main() { printf("bar"); }
key-duplicates
Use this rule to prevent multiple entries with the same key in mappings.
Options
Use
forbid-duplicated-merge-keysto forbid the usage of multiple merge keys<<.
Default values (when enabled)
rules:
key-duplicates:
forbid-duplicated-merge-keys: false
Examples
With
key-duplicates: {}the following code snippet would PASS:
- key 1: v key 2: val key 3: value - {a: 1, b: 2, c: 3}
the following code snippet would FAIL:
- key 1: v key 2: val key 1: value
the following code snippet would FAIL:
- {a: 1, b: 2, b: 3}
the following code snippet would FAIL:
duplicated key: 1 "duplicated key": 2 other duplication: 1 ? >- other duplication : 2With
key-duplicates: {forbid-duplicated-merge-keys: true}the following code snippet would PASS:
anchor_one: &anchor_one one: one anchor_two: &anchor_two two: two anchor_reference: <<: [*anchor_one, *anchor_two]
the following code snippet would FAIL:
anchor_one: &anchor_one one: one anchor_two: &anchor_two two: two anchor_reference: <<: *anchor_one <<: *anchor_two
key-ordering
Use this rule to enforce alphabetical ordering of keys in mappings. The sorting
order uses the Unicode code point number as a default. As a result, the
ordering is case-sensitive and not accent-friendly (see examples below).
This can be changed by setting the global locale option. This allows one
to sort case and accents properly.
Options
ignored-keysis a list of PCRE regexes to ignore some keys while checking order, if they match any regex.
Default values (when enabled)
rules:
key-ordering:
ignored-keys: []
Examples
With
key-ordering: {}the following code snippet would PASS:
- key 1: v key 2: val key 3: value - {a: 1, b: 2, c: 3} - T-shirt: 1 T-shirts: 2 t-shirt: 3 t-shirts: 4 - hair: true hais: true haïr: true haïssable: true
the following code snippet would FAIL:
- key 2: v key 1: val
the following code snippet would FAIL:
- {b: 1, a: 2}
the following code snippet would FAIL:
- T-shirt: 1 t-shirt: 2 T-shirts: 3 t-shirts: 4
the following code snippet would FAIL:
- haïr: true hais: true
With global option
locale: "en_US.UTF-8"and rulekey-ordering: {}as opposed to before, the following code snippet would now PASS:
- t-shirt: 1 T-shirt: 2 t-shirts: 3 T-shirts: 4 - hair: true haïr: true hais: true haïssable: true
With rule
key-ordering: {ignored-keys: ["name"]}the following code snippet would PASS:
- a: b: name: ignored first-name: ignored c: d:
line-length
Use this rule to set a limit to lines length.
Options
maxdefines the maximal (inclusive) length of lines.allow-non-breakable-wordsis used to allow non breakable words (without spaces inside) to overflow the limit. This is useful for long URLs, for instance. Usetrueto allow,falseto forbid.allow-non-breakable-inline-mappingsimpliesallow-non-breakable-wordsand extends it to also allow non-breakable words in inline mappings.
Default values (when enabled)
rules:
line-length:
max: 80
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: false
Examples
With
line-length: {max: 70}the following code snippet would PASS:
long sentence: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
the following code snippet would FAIL:
long sentence: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
With
line-length: {max: 60, allow-non-breakable-words: true}the following code snippet would PASS:
this: is: - a: http://localhost/very/very/very/very/very/very/very/very/long/url # this comment is too long, # but hard to split: # http://localhost/another/very/very/very/very/very/very/very/very/long/url
the following code snippet would FAIL:
- this line is waaaaaaaaaaaaaay too long but could be easily split...
and the following code snippet would also FAIL:
- foobar: http://localhost/very/very/very/very/very/very/very/very/long/url
With
line-length: {max: 60, allow-non-breakable-words: true, allow-non-breakable-inline-mappings: true}the following code snippet would PASS:
- foobar: http://localhost/very/very/very/very/very/very/very/very/long/url
With
line-length: {max: 60, allow-non-breakable-words: false}the following code snippet would FAIL:
this: is: - a: http://localhost/very/very/very/very/very/very/very/very/long/url
new-line-at-end-of-file
Use this rule to require a new line character (\n) at the end of files.
The POSIX standard requires the last line to end with a new line character. All UNIX tools expect a new line at the end of files. Most text editors use this convention too.
new-lines
Use this rule to force the type of new line characters.
Options
Set
typetounixto enforce UNIX-typed new line characters (\n), settypetodosto enforce DOS-typed new line characters (\r\n), or settypetoplatformto infer the type from the system running yamllint (\non POSIX / UNIX / Linux / Mac OS systems or\r\non DOS / Windows systems).
Default values (when enabled)
rules:
new-lines:
type: unix
octal-values
Use this rule to prevent values with octal numbers. In YAML, numbers that
start with 0 are interpreted as octal, but this is not always wanted.
For instance 010 is the city code of Beijing, and should not be
converted to 8.
Options
Use
forbid-implicit-octalto prevent numbers starting with0.Use
forbid-explicit-octalto prevent numbers starting with0o.
Default values (when enabled)
rules:
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
Examples
With
octal-values: {forbid-implicit-octal: true}the following code snippets would PASS:
user: city-code: '010'
the following code snippets would PASS:
user: city-code: 010,021
the following code snippets would FAIL:
user: city-code: 010
With
octal-values: {forbid-explicit-octal: true}the following code snippets would PASS:
user: city-code: '0o10'
the following code snippets would FAIL:
user: city-code: 0o10
quoted-strings
Use this rule to forbid any string values that are not quoted, or to prevent quoted strings without needing it. You can also enforce the type of the quote used.
Options
quote-typedefines allowed quotes:single,doubleorany(default).requireddefines whether using quotes in string values is required (true, default) or not (false), or only allowed when really needed (only-when-needed).extra-requiredis a list of PCRE regexes to force string values to be quoted, if they match any regex. This option can only be used withrequired: falseandrequired: only-when-needed.extra-allowedis a list of PCRE regexes to allow quoted string values, even ifrequired: only-when-neededis set.allow-quoted-quotesallows (true) using disallowed quotes for strings with allowed quotes inside. Defaultfalse.check-keysdefines whether to apply the rules to keys in mappings. By default,quoted-stringsrules apply only to values. Set this option totrueto apply the rules to keys as well.
Note: Multi-line strings (with | or >) will not be checked.
Default values (when enabled)
rules:
quoted-strings:
quote-type: any
required: true
extra-required: []
extra-allowed: []
allow-quoted-quotes: false
check-keys: false
Examples
With
quoted-strings: {quote-type: any, required: true}the following code snippet would PASS:
foo: "bar" bar: 'foo' number: 123 boolean: true
the following code snippet would FAIL:
foo: bar
With
quoted-strings: {quote-type: single, required: only-when-needed}the following code snippet would PASS:
foo: bar bar: foo not_number: '123' not_boolean: 'true' not_comment: '# comment' not_list: '[1, 2, 3]' not_map: '{a: 1, b: 2}'
the following code snippet would FAIL:
foo: 'bar'
With
quoted-strings: {required: false, extra-required: [^http://, ^ftp://]}the following code snippet would PASS:
- localhost - "localhost" - "http://localhost" - "ftp://localhost"
the following code snippet would FAIL:
- http://localhost - ftp://localhost
With
quoted-strings: {required: only-when-needed, extra-allowed: [^http://, ^ftp://], extra-required: [QUOTED]}the following code snippet would PASS:
- localhost - "http://localhost" - "ftp://localhost" - "this is a string that needs to be QUOTED"
the following code snippet would FAIL:
- "localhost" - this is a string that needs to be QUOTED
With
quoted-strings: {quote-type: double, allow-quoted-quotes: false}the following code snippet would PASS:
foo: "bar\"baz"
the following code snippet would FAIL:
foo: 'bar"baz'
With
quoted-strings: {quote-type: double, allow-quoted-quotes: true}the following code snippet would PASS:
foo: 'bar"baz'
With
quoted-strings: {required: only-when-needed, check-keys: true, extra-required: ["[:]"]}the following code snippet would FAIL:
foo:bar: baz
the following code snippet would PASS:
"foo:bar": baz
trailing-spaces
Use this rule to forbid trailing spaces at the end of lines.
Examples
With
trailing-spaces: {}the following code snippet would PASS:
this document doesn't contain any trailing spaces
the following code snippet would FAIL:
this document contains trailing spaces on lines 1 and 3
truthy
Use this rule to forbid non-explicitly typed truthy values other than allowed
ones (by default: true and false), for example YES or off.
This can be useful to prevent surprises from YAML parsers transforming
[yes, FALSE, Off] into [true, false, false] or
{y: 1, yes: 2, on: 3, true: 4, True: 5} into {y: 1, true: 5}.
Depending on the YAML specification version used by the YAML document, the list
of truthy values can differ. In YAML 1.2, only capitalized / uppercased
combinations of true and false are considered truthy, whereas in YAML
1.1 combinations of yes, no, on and off are too. To make the
YAML specification version explicit in a YAML document, a %YAML 1.2
directive can be used (see example below).
Options
allowed-valuesdefines the list of truthy values which will be ignored during linting. The default is['true', 'false'], but can be changed to any list containing:'TRUE','True','true','FALSE','False','false','YES','Yes','yes','NO','No','no','ON','On','on','OFF','Off','off'.check-keysdisables verification for keys in mappings. By default,truthyrule applies to both keys and values. Set this option tofalseto prevent this.
Default values (when enabled)
rules:
truthy:
allowed-values: ['true', 'false']
check-keys: true
Examples
With
truthy: {}the following code snippet would PASS:
boolean: true object: {"True": 1, 1: "True"} "yes": 1 "on": 2 "True": 3 explicit: string1: !!str True string2: !!str yes string3: !!str off encoded: !!binary | True OFF pad== # this decodes as 'N»8Qii' boolean1: !!bool true boolean2: !!bool "false" boolean3: !!bool FALSE boolean4: !!bool True boolean5: !!bool off boolean6: !!bool NOthe following code snippet would FAIL:
object: {True: 1, 1: True}
the following code snippet would FAIL:
%YAML 1.1 --- yes: 1 on: 2 True: 3
the following code snippet would PASS:
%YAML 1.2 --- yes: 1 on: 2 true: 3
With
truthy: {allowed-values: ["yes", "no"]}the following code snippet would PASS:
- yes - no - "true" - 'false' - foo - bar
the following code snippet would FAIL:
- true - false - on - off
With
truthy: {check-keys: false}the following code snippet would PASS:
yes: 1 on: 2 true: 3
the following code snippet would FAIL:
yes: Yes on: On true: True