1YAMLLINT(1)                        yamllint                        YAMLLINT(1)
2
3
4

NAME

6       yamllint - Linter for YAML files
7
8       A linter for YAML files.
9
10       yamllint  does  not only check for syntax validity, but for weirdnesses
11       like key repetition and cosmetic problems such as lines length,  trail‐
12       ing spaces, indentation, etc.
13

SCREENSHOT

15       [image: yamllint screenshot] [image]
16
17       NOTE:
18          The  default  output  format  is inspired by eslint, a great linting
19          tool for Javascript.
20

TABLE OF CONTENTS

22   Quickstart
23   Installing yamllint
24       On Fedora / CentOS (note: EPEL is required on CentOS):
25
26          sudo dnf install yamllint
27
28       On Debian 8+ / Ubuntu 16.04+:
29
30          sudo apt-get install yamllint
31
32       On Mac OS 10.11+:
33
34          brew install yamllint
35
36       On FreeBSD:
37
38          pkg install py36-yamllint
39
40       On OpenBSD:
41
42          doas pkg_add py3-yamllint
43
44       Alternatively using pip, the Python package manager:
45
46          pip install --user yamllint
47
48       If you prefer installing from source, you can run, from the source  di‐
49       rectory:
50
51          python -m build
52          pip install --user dist/yamllint-*.tar.gz
53
54   Running yamllint
55       Basic usage:
56
57          yamllint file.yml other-file.yaml
58
59       You can also lint all YAML files in a whole directory:
60
61          yamllint .
62
63       Or lint a YAML stream from standard input:
64
65          echo -e 'this: is\nvalid: YAML' | yamllint -
66
67       The output will look like (colors are not displayed here):
68
69          file.yml
70            1:4       error    trailing spaces  (trailing-spaces)
71            4:4       error    wrong indentation: expected 4 but found 3  (indentation)
72            5:4       error    duplication of key "id-00042" in mapping  (key-duplicates)
73            6:6       warning  comment not indented like content  (comments-indentation)
74            12:6      error    too many spaces after hyphen  (hyphens)
75            15:12     error    too many spaces before comma  (commas)
76
77          other-file.yaml
78            1:1       warning  missing document start "---"  (document-start)
79            6:81      error    line too long (87 > 80 characters)  (line-length)
80            10:1      error    too many blank lines (4 > 2)  (empty-lines)
81            11:4      error    too many spaces inside braces  (braces)
82
83       By default, the output of yamllint is colored when run from a terminal,
84       and pure text in other cases. Add the -f standard  arguments  to  force
85       non-colored  output. Use the -f colored arguments to force colored out‐
86       put.
87
88       Add the -f parsable arguments if you need an output format parsable  by
89       a  machine  (for instance for syntax highlighting in text editors). The
90       output will then look like:
91
92          file.yml:6:2: [warning] missing starting space in comment (comments)
93          file.yml:57:1: [error] trailing spaces (trailing-spaces)
94          file.yml:60:3: [error] wrong indentation: expected 4 but found 2 (indentation)
95
96       If you have a custom linting configuration file (see how  to  configure
97       yamllint), it can be passed to yamllint using the -c option:
98
99          yamllint -c ~/myconfig file.yaml
100
101       NOTE:
102          If  you  have a .yamllint file in your working directory, it will be
103          automatically loaded as configuration by yamllint.
104
105   Configuration
106       yamllint uses a set of rules to check source files for problems.   Each
107       rule  is  independent  from the others, and can be enabled, disabled or
108       tweaked. All these settings can be gathered in a configuration file.
109
110       To use a custom configuration file, use the -c option:
111
112          yamllint -c /path/to/myconfig file-to-lint.yaml
113
114       If -c is not provided, yamllint will look for a configuration  file  in
115       the following locations (by order of preference):
116
117       • a  file named .yamllint, .yamllint.yaml, or .yamllint.yml in the cur‐
118         rent working directory, or a parent directory (the  search  for  this
119         file is terminated at the user's home or filesystem root)
120
121       • a filename referenced by $YAMLLINT_CONFIG_FILE, if set
122
123       • a   file  named  $XDG_CONFIG_HOME/yamllint/config  or  ~/.config/yam‐
124         llint/config, if present
125
126       Finally if no config file is found, the default  configuration  is  ap‐
127       plied.
128
129   Default configuration
130       Unless told otherwise, yamllint uses its default configuration:
131
132          ---
133
134          yaml-files:
135            - '*.yaml'
136            - '*.yml'
137            - '.yamllint'
138
139          rules:
140            anchors: enable
141            braces: enable
142            brackets: enable
143            colons: enable
144            commas: enable
145            comments:
146              level: warning
147            comments-indentation:
148              level: warning
149            document-end: disable
150            document-start:
151              level: warning
152            empty-lines: enable
153            empty-values: disable
154            float-values: disable
155            hyphens: enable
156            indentation: enable
157            key-duplicates: enable
158            key-ordering: disable
159            line-length: enable
160            new-line-at-end-of-file: enable
161            new-lines: enable
162            octal-values: disable
163            quoted-strings: disable
164            trailing-spaces: enable
165            truthy:
166              level: warning
167
168
169       Details on rules can be found on the rules page.
170
171       There  is  another pre-defined configuration named relaxed. As its name
172       suggests, it is more tolerant:
173
174          ---
175
176          extends: default
177
178          rules:
179            braces:
180              level: warning
181              max-spaces-inside: 1
182            brackets:
183              level: warning
184              max-spaces-inside: 1
185            colons:
186              level: warning
187            commas:
188              level: warning
189            comments: disable
190            comments-indentation: disable
191            document-start: disable
192            empty-lines:
193              level: warning
194            hyphens:
195              level: warning
196            indentation:
197              level: warning
198              indent-sequences: consistent
199            line-length:
200              level: warning
201              allow-non-breakable-inline-mappings: true
202            truthy: disable
203
204
205       It can be chosen using:
206
207          yamllint -d relaxed file.yml
208
209   Extending the default configuration
210       When writing a custom configuration file, you don't  need  to  redefine
211       every  rule.  Just extend the default configuration (or any already-ex‐
212       isting configuration file).
213
214       For instance, if you just  want  to  disable  the  comments-indentation
215       rule, your file could look like this:
216
217          # This is my first, very own configuration file for yamllint!
218          # It extends the default conf by adjusting some options.
219
220          extends: default
221
222          rules:
223            comments-indentation: disable  # don't bother me with this rule
224
225       Similarly,  if you want to set the line-length rule as a warning and be
226       less strict on block sequences indentation:
227
228          extends: default
229
230          rules:
231            # 80 chars should be enough, but don't fail if a line is longer
232            line-length:
233              max: 80
234              level: warning
235
236            # accept both     key:
237            #                   - item
238            #
239            # and             key:
240            #                 - item
241            indentation:
242              indent-sequences: whatever
243
244   Custom configuration without a config file
245       It is possible -- although not recommended -- to pass custom configura‐
246       tion options to yamllint with the -d (short for --config-data) option.
247
248       Its  content can either be the name of a pre-defined conf (example: de‐
249       fault or relaxed) or a serialized YAML object describing the configura‐
250       tion.
251
252       For instance:
253
254          yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" file.yaml
255
256   Errors and warnings
257       Problems  detected  by  yamllint  can  be raised either as errors or as
258       warnings.  The CLI will output them (with different colors  when  using
259       the colored output format, or auto when run from a terminal).
260
261       By default the script will exit with a return code 1 only when there is
262       one or more error(s).
263
264       However if strict mode is enabled with the -s (or --strict) option, the
265       return code will be:
266
2670 if no errors or warnings occur
268
2691 if one or more errors occur
270
2712 if no errors occur, but one or more warnings occur
272
273       If the script is invoked with the --no-warnings option, it won't output
274       warning level problems, only error level ones.
275
276   YAML files extensions
277       To configure what yamllint should consider as YAML files  when  listing
278       directories, set yaml-files configuration option. The default is:
279
280          yaml-files:
281            - '*.yaml'
282            - '*.yml'
283            - '.yamllint'
284
285       The  same rules as for ignoring paths apply (.gitignore-style path pat‐
286       tern, see below).
287
288       If you need to know  the  exact  list  of  files  that  yamllint  would
289       process, without really linting them, you can use --list-files:
290
291          yamllint --list-files .
292
293   Ignoring paths
294       It  is  possible  to exclude specific files or directories, so that the
295       linter doesn't process them. They can be provided either as a  list  of
296       paths, or as a bulk string.
297
298       You can either totally ignore files (they won't be looked at):
299
300          extends: default
301
302          ignore: |
303            /this/specific/file.yaml
304            all/this/directory/
305            *.template.yaml
306
307          # or:
308
309          ignore:
310            - /this/specific/file.yaml
311            - all/this/directory/
312            - '*.template.yaml'
313
314       or ignore paths only for specific rules:
315
316          extends: default
317
318          rules:
319            trailing-spaces:
320              ignore: |
321                /this-file-has-trailing-spaces-but-it-is-OK.yaml
322                /generated/*.yaml
323
324          # or:
325
326          rules:
327            trailing-spaces:
328              ignore:
329                - /this-file-has-trailing-spaces-but-it-is-OK.yaml
330                - /generated/*.yaml
331
332       Note that this .gitignore-style path pattern allows complex path exclu‐
333       sion/inclusion, see the pathspec README file for more details. Here  is
334       a more complex example:
335
336          # For all rules
337          ignore: |
338            *.dont-lint-me.yaml
339            /bin/
340            !/bin/*.lint-me-anyway.yaml
341
342          extends: default
343
344          rules:
345            key-duplicates:
346              ignore: |
347                generated
348                *.template.yaml
349            trailing-spaces:
350              ignore: |
351                *.ignore-trailing-spaces.yaml
352                ascii-art/*
353
354       You can also use the .gitignore file (or any list of files) through:
355
356          ignore-from-file: .gitignore
357
358       or:
359
360          ignore-from-file: [.gitignore, .yamlignore]
361
362       NOTE:
363          However, this is mutually exclusive with the ignore key.
364
365       If  you  need  to  know  the  exact  list  of files that yamllint would
366       process, without really linting them, you can use --list-files:
367
368          yamllint --list-files .
369
370   Setting the locale
371       It is possible to set the locale option globally.  This  is  passed  to
372       Python's  locale.setlocale,  so  an empty string "" will use the system
373       default locale, while e.g.  "en_US.UTF-8" will use that.
374
375       Currently this only affects the key-ordering rule. The default will or‐
376       der  by Unicode code point number, while locales will sort case and ac‐
377       cents properly as well.
378
379          extends: default
380
381          locale: en_US.UTF-8
382
383   Rules
384       When linting a document with yamllint,  a  series  of  rules  (such  as
385       line-length, trailing-spaces, etc.) are checked against.
386
387       A  configuration  file can be used to enable or disable these rules, to
388       set their level (error or warning), but also to tweak their options.
389
390       This page describes the rules and their options.
391
392   List of rules
393anchors
394
395braces
396
397brackets
398
399colons
400
401commas
402
403comments
404
405comments-indentation
406
407document-end
408
409document-start
410
411empty-lines
412
413empty-values
414
415float-values
416
417hyphens
418
419indentation
420
421key-duplicates
422
423key-ordering
424
425line-length
426
427new-line-at-end-of-file
428
429new-lines
430
431octal-values
432
433quoted-strings
434
435trailing-spaces
436
437truthy
438
439   anchors
440       Use this rule to report duplicated anchors and aliases referencing  un‐
441       declared anchors.
442
443       Options
444
445       • Set forbid-undeclared-aliases to true to avoid aliases that reference
446         an anchor that hasn't been declared (either not declared at  all,  or
447         declared later in the document).
448
449       • Set forbid-duplicated-anchors to true to avoid duplications of a same
450         anchor.
451
452       • Set forbid-unused-anchors to true to avoid anchors being declared but
453         not used anywhere in the YAML document via alias.
454
455       Default values (when enabled)
456
457          rules:
458            anchors:
459              forbid-undeclared-aliases: true
460              forbid-duplicated-anchors: false
461              forbid-unused-anchors: false
462
463       Examples
464
465       1. With anchors: {forbid-undeclared-aliases: true}
466
467          the following code snippet would PASS:
468
469             ---
470             - &anchor
471               foo: bar
472             - *anchor
473
474          the following code snippet would FAIL:
475
476             ---
477             - &anchor
478               foo: bar
479             - *unknown
480
481          the following code snippet would FAIL:
482
483             ---
484             - &anchor
485               foo: bar
486             - <<: *unknown
487               extra: value
488
489       2. With anchors: {forbid-duplicated-anchors: true}
490
491          the following code snippet would PASS:
492
493             ---
494             - &anchor1 Foo Bar
495             - &anchor2 [item 1, item 2]
496
497          the following code snippet would FAIL:
498
499             ---
500             - &anchor Foo Bar
501             - &anchor [item 1, item 2]
502
503       3. With anchors: {forbid-unused-anchors: true}
504
505          the following code snippet would PASS:
506
507             ---
508             - &anchor
509               foo: bar
510             - *anchor
511
512          the following code snippet would FAIL:
513
514             ---
515             - &anchor
516               foo: bar
517             - items:
518               - item1
519               - item2
520
521   braces
522       Use  this  rule to control the use of flow mappings or number of spaces
523       inside braces ({ and }).
524
525       Options
526
527forbid is used to forbid the use of flow mappings which  are  denoted
528         by  surrounding  braces ({ and }). Use true to forbid the use of flow
529         mappings completely. Use non-empty to forbid the use of all flow map‐
530         pings except for empty ones.
531
532min-spaces-inside  defines  the minimal number of spaces required in‐
533         side braces.
534
535max-spaces-inside defines the maximal number of spaces allowed inside
536         braces.
537
538min-spaces-inside-empty defines the minimal number of spaces required
539         inside empty braces.
540
541max-spaces-inside-empty defines the maximal number of spaces  allowed
542         inside empty braces.
543
544       Default values (when enabled)
545
546          rules:
547            braces:
548              forbid: false
549              min-spaces-inside: 0
550              max-spaces-inside: 0
551              min-spaces-inside-empty: -1
552              max-spaces-inside-empty: -1
553
554       Examples
555
556       1. With braces: {forbid: true}
557
558          the following code snippet would PASS:
559
560             object:
561               key1: 4
562               key2: 8
563
564          the following code snippet would FAIL:
565
566             object: { key1: 4, key2: 8 }
567
568       2. With braces: {forbid: non-empty}
569
570          the following code snippet would PASS:
571
572             object: {}
573
574          the following code snippet would FAIL:
575
576             object: { key1: 4, key2: 8 }
577
578       3. With braces: {min-spaces-inside: 0, max-spaces-inside: 0}
579
580          the following code snippet would PASS:
581
582             object: {key1: 4, key2: 8}
583
584          the following code snippet would FAIL:
585
586             object: { key1: 4, key2: 8 }
587
588       4. With braces: {min-spaces-inside: 1, max-spaces-inside: 3}
589
590          the following code snippet would PASS:
591
592             object: { key1: 4, key2: 8 }
593
594          the following code snippet would PASS:
595
596             object: { key1: 4, key2: 8   }
597
598          the following code snippet would FAIL:
599
600             object: {    key1: 4, key2: 8   }
601
602          the following code snippet would FAIL:
603
604             object: {key1: 4, key2: 8 }
605
606       5. With  braces:  {min-spaces-inside-empty: 0, max-spaces-inside-empty:
607          0}
608
609          the following code snippet would PASS:
610
611             object: {}
612
613          the following code snippet would FAIL:
614
615             object: { }
616
617       6. With braces: {min-spaces-inside-empty:  1,  max-spaces-inside-empty:
618          -1}
619
620          the following code snippet would PASS:
621
622             object: {         }
623
624          the following code snippet would FAIL:
625
626             object: {}
627
628   brackets
629       Use  this  rule  to  control the use of flow sequences or the number of
630       spaces inside brackets ([ and ]).
631
632       Options
633
634forbid is used to forbid the use of flow sequences which are  denoted
635         by surrounding brackets ([ and ]). Use true to forbid the use of flow
636         sequences completely. Use non-empty to forbid the use of all flow se‐
637         quences except for empty ones.
638
639min-spaces-inside  defines  the minimal number of spaces required in‐
640         side brackets.
641
642max-spaces-inside defines the maximal number of spaces allowed inside
643         brackets.
644
645min-spaces-inside-empty defines the minimal number of spaces required
646         inside empty brackets.
647
648max-spaces-inside-empty defines the maximal number of spaces  allowed
649         inside empty brackets.
650
651       Default values (when enabled)
652
653          rules:
654            brackets:
655              forbid: false
656              min-spaces-inside: 0
657              max-spaces-inside: 0
658              min-spaces-inside-empty: -1
659              max-spaces-inside-empty: -1
660
661       Examples
662
663       1. With brackets: {forbid: true}
664
665          the following code snippet would PASS:
666
667             object:
668               - 1
669               - 2
670               - abc
671
672          the following code snippet would FAIL:
673
674             object: [ 1, 2, abc ]
675
676       2. With brackets: {forbid: non-empty}
677
678          the following code snippet would PASS:
679
680             object: []
681
682          the following code snippet would FAIL:
683
684             object: [ 1, 2, abc ]
685
686       3. With brackets: {min-spaces-inside: 0, max-spaces-inside: 0}
687
688          the following code snippet would PASS:
689
690             object: [1, 2, abc]
691
692          the following code snippet would FAIL:
693
694             object: [ 1, 2, abc ]
695
696       4. With brackets: {min-spaces-inside: 1, max-spaces-inside: 3}
697
698          the following code snippet would PASS:
699
700             object: [ 1, 2, abc ]
701
702          the following code snippet would PASS:
703
704             object: [ 1, 2, abc   ]
705
706          the following code snippet would FAIL:
707
708             object: [    1, 2, abc   ]
709
710          the following code snippet would FAIL:
711
712             object: [1, 2, abc ]
713
714       5. With brackets: {min-spaces-inside-empty: 0, max-spaces-inside-empty:
715          0}
716
717          the following code snippet would PASS:
718
719             object: []
720
721          the following code snippet would FAIL:
722
723             object: [ ]
724
725       6. With brackets: {min-spaces-inside-empty: 1, max-spaces-inside-empty:
726          -1}
727
728          the following code snippet would PASS:
729
730             object: [         ]
731
732          the following code snippet would FAIL:
733
734             object: []
735
736   colons
737       Use  this  rule to control the number of spaces before and after colons
738       (:).
739
740       Options
741
742max-spaces-before defines the maximal number of spaces allowed before
743         colons (use -1 to disable).
744
745max-spaces-after  defines  the maximal number of spaces allowed after
746         colons (use -1 to disable).
747
748       Default values (when enabled)
749
750          rules:
751            colons:
752              max-spaces-before: 0
753              max-spaces-after: 1
754
755       Examples
756
757       1. With colons: {max-spaces-before: 0, max-spaces-after: 1}
758
759          the following code snippet would PASS:
760
761             object:
762               - a
763               - b
764             key: value
765
766       2. With colons: {max-spaces-before: 1}
767
768          the following code snippet would PASS:
769
770             object :
771               - a
772               - b
773
774          the following code snippet would FAIL:
775
776             object  :
777               - a
778               - b
779
780       3. With colons: {max-spaces-after: 2}
781
782          the following code snippet would PASS:
783
784             first:  1
785             second: 2
786             third:  3
787
788          the following code snippet would FAIL:
789
790             first: 1
791             2nd:   2
792             third: 3
793
794   commas
795       Use this rule to control the number of spaces before and  after  commas
796       (,).
797
798       Options
799
800max-spaces-before defines the maximal number of spaces allowed before
801         commas (use -1 to disable).
802
803min-spaces-after defines the minimal number of spaces required  after
804         commas.
805
806max-spaces-after  defines  the maximal number of spaces allowed after
807         commas (use -1 to disable).
808
809       Default values (when enabled)
810
811          rules:
812            commas:
813              max-spaces-before: 0
814              min-spaces-after: 1
815              max-spaces-after: 1
816
817       Examples
818
819       1. With commas: {max-spaces-before: 0}
820
821          the following code snippet would PASS:
822
823             strange var:
824               [10, 20, 30, {x: 1, y: 2}]
825
826          the following code snippet would FAIL:
827
828             strange var:
829               [10, 20 , 30, {x: 1, y: 2}]
830
831       2. With commas: {max-spaces-before: 2}
832
833          the following code snippet would PASS:
834
835             strange var:
836               [10  , 20 , 30,  {x: 1  , y: 2}]
837
838       3. With commas: {max-spaces-before: -1}
839
840          the following code snippet would PASS:
841
842             strange var:
843               [10,
844                20   , 30
845                ,   {x: 1, y: 2}]
846
847       4. With commas: {min-spaces-after: 1, max-spaces-after: 1}
848
849          the following code snippet would PASS:
850
851             strange var:
852               [10, 20, 30, {x: 1, y: 2}]
853
854          the following code snippet would FAIL:
855
856             strange var:
857               [10, 20,30,   {x: 1,   y: 2}]
858
859       5. With commas: {min-spaces-after: 1, max-spaces-after: 3}
860
861          the following code snippet would PASS:
862
863             strange var:
864               [10, 20,  30,  {x: 1,   y: 2}]
865
866       6. With commas: {min-spaces-after: 0, max-spaces-after: 1}
867
868          the following code snippet would PASS:
869
870             strange var:
871               [10, 20,30, {x: 1, y: 2}]
872
873   comments
874       Use this rule to control the position and formatting of comments.
875
876       Options
877
878       • Use require-starting-space to require a space character  right  after
879         the #. Set to true to enable, false to disable.
880
881       • Use  ignore-shebangs to ignore a shebang at the beginning of the file
882         when require-starting-space is set.
883
884min-spaces-from-content is used to visually separate inline  comments
885         from  content.  It  defines the minimal required number of spaces be‐
886         tween a comment and its preceding content.
887
888       Default values (when enabled)
889
890          rules:
891            comments:
892              require-starting-space: true
893              ignore-shebangs: true
894              min-spaces-from-content: 2
895
896       Examples
897
898       1. With comments: {require-starting-space: true}
899
900          the following code snippet would PASS:
901
902             # This sentence
903             # is a block comment
904
905          the following code snippet would PASS:
906
907             ##############################
908             ## This is some documentation
909
910          the following code snippet would FAIL:
911
912             #This sentence
913             #is a block comment
914
915       2. With comments: {min-spaces-from-content: 2}
916
917          the following code snippet would PASS:
918
919             x = 2 ^ 127 - 1  # Mersenne prime number
920
921          the following code snippet would FAIL:
922
923             x = 2 ^ 127 - 1 # Mersenne prime number
924
925   comments-indentation
926       Use this rule to force comments to be indented like content.
927
928       Examples
929
930       1. With comments-indentation: {}
931
932          the following code snippet would PASS:
933
934             # Fibonacci
935             [0, 1, 1, 2, 3, 5]
936
937          the following code snippet would FAIL:
938
939               # Fibonacci
940             [0, 1, 1, 2, 3, 5]
941
942          the following code snippet would PASS:
943
944             list:
945                 - 2
946                 - 3
947                 # - 4
948                 - 5
949
950          the following code snippet would FAIL:
951
952             list:
953                 - 2
954                 - 3
955             #    - 4
956                 - 5
957
958          the following code snippet would PASS:
959
960             # This is the first object
961             obj1:
962               - item A
963               # - item B
964             # This is the second object
965             obj2: []
966
967          the following code snippet would PASS:
968
969             # This sentence
970             # is a block comment
971
972          the following code snippet would FAIL:
973
974             # This sentence
975              # is a block comment
976
977   document-end
978       Use this rule to require or forbid  the  use  of  document  end  marker
979       (...).
980
981       Options
982
983       • Set  present  to true when the document end marker is required, or to
984         false when it is forbidden.
985
986       Default values (when enabled)
987
988          rules:
989            document-end:
990              present: true
991
992       Examples
993
994       1. With document-end: {present: true}
995
996          the following code snippet would PASS:
997
998             ---
999             this:
1000               is: [a, document]
1001             ...
1002             ---
1003             - this
1004             - is: another one
1005             ...
1006
1007          the following code snippet would FAIL:
1008
1009             ---
1010             this:
1011               is: [a, document]
1012             ---
1013             - this
1014             - is: another one
1015             ...
1016
1017       2. With document-end: {present: false}
1018
1019          the following code snippet would PASS:
1020
1021             ---
1022             this:
1023               is: [a, document]
1024             ---
1025             - this
1026             - is: another one
1027
1028          the following code snippet would FAIL:
1029
1030             ---
1031             this:
1032               is: [a, document]
1033             ...
1034             ---
1035             - this
1036             - is: another one
1037
1038   document-start
1039       Use this rule to require or forbid the use  of  document  start  marker
1040       (---).
1041
1042       Options
1043
1044       • Set present to true when the document start marker is required, or to
1045         false when it is forbidden.
1046
1047       Default values (when enabled)
1048
1049          rules:
1050            document-start:
1051              present: true
1052
1053       Examples
1054
1055       1. With document-start: {present: true}
1056
1057          the following code snippet would PASS:
1058
1059             ---
1060             this:
1061               is: [a, document]
1062             ---
1063             - this
1064             - is: another one
1065
1066          the following code snippet would FAIL:
1067
1068             this:
1069               is: [a, document]
1070             ---
1071             - this
1072             - is: another one
1073
1074       2. With document-start: {present: false}
1075
1076          the following code snippet would PASS:
1077
1078             this:
1079               is: [a, document]
1080             ...
1081
1082          the following code snippet would FAIL:
1083
1084             ---
1085             this:
1086               is: [a, document]
1087             ...
1088
1089   empty-lines
1090       Use this rule to set a maximal  number  of  allowed  consecutive  blank
1091       lines.
1092
1093       Options
1094
1095max  defines  the  maximal number of empty lines allowed in the docu‐
1096         ment.
1097
1098max-start defines the maximal number of empty lines  allowed  at  the
1099         beginning of the file. This option takes precedence over max.
1100
1101max-end  defines the maximal number of empty lines allowed at the end
1102         of the file.  This option takes precedence over max.
1103
1104       Default values (when enabled)
1105
1106          rules:
1107            empty-lines:
1108              max: 2
1109              max-start: 0
1110              max-end: 0
1111
1112       Examples
1113
1114       1. With empty-lines: {max: 1}
1115
1116          the following code snippet would PASS:
1117
1118             - foo:
1119                 - 1
1120                 - 2
1121
1122             - bar: [3, 4]
1123
1124          the following code snippet would FAIL:
1125
1126             - foo:
1127                 - 1
1128                 - 2
1129
1130
1131             - bar: [3, 4]
1132
1133   empty-values
1134       Use this rule to prevent nodes with empty content, that implicitly  re‐
1135       sult in null values.
1136
1137       Options
1138
1139       • Use  forbid-in-block-mappings  to  prevent empty values in block map‐
1140         pings.
1141
1142       • Use forbid-in-flow-mappings to prevent empty values in flow mappings.
1143
1144       • Use forbid-in-block-sequences to prevent empty values  in  block  se‐
1145         quences.
1146
1147       Default values (when enabled)
1148
1149          rules:
1150            empty-values:
1151              forbid-in-block-mappings: true
1152              forbid-in-flow-mappings: true
1153              forbid-in-block-sequences: true
1154
1155       Examples
1156
1157       1. With empty-values: {forbid-in-block-mappings: true}
1158
1159          the following code snippets would PASS:
1160
1161             some-mapping:
1162               sub-element: correctly indented
1163
1164             explicitly-null: null
1165
1166          the following code snippets would FAIL:
1167
1168             some-mapping:
1169             sub-element: incorrectly indented
1170
1171             implicitly-null:
1172
1173       2. With empty-values: {forbid-in-flow-mappings: true}
1174
1175          the following code snippet would PASS:
1176
1177             {prop: null}
1178             {a: 1, b: 2, c: 3}
1179
1180          the following code snippets would FAIL:
1181
1182             {prop: }
1183
1184             {a: 1, b:, c: 3}
1185
1186       3. With empty-values: {forbid-in-block-sequences: true}
1187
1188          the following code snippet would PASS:
1189
1190             some-sequence:
1191               - string item
1192
1193             some-sequence:
1194               - null
1195
1196          the following code snippets would FAIL:
1197
1198             some-sequence:
1199               -
1200
1201             some-sequence:
1202               - string item
1203               -
1204
1205   float-values
1206       Use this rule to limit the permitted values for floating-point numbers.
1207       YAML permits three classes of float expressions: approximation to  real
1208       numbers, positive and negative infinity and "not a number".
1209
1210       Options
1211
1212       • Use  require-numeral-before-decimal to require floats to start with a
1213         numeral (ex 0.0 instead of .0).
1214
1215       • Use forbid-scientific-notation to forbid scientific notation.
1216
1217       • Use forbid-nan to forbid NaN (not a number) values.
1218
1219       • Use forbid-inf to forbid infinite values.
1220
1221       Default values (when enabled)
1222
1223          rules:
1224            float-values:
1225              forbid-inf: false
1226              forbid-nan: false
1227              forbid-scientific-notation: false
1228              require-numeral-before-decimal: false
1229
1230       Examples
1231
1232       1. With float-values: {require-numeral-before-decimal: true}
1233
1234          the following code snippets would PASS:
1235
1236             anemometer:
1237               angle: 0.0
1238
1239          the following code snippets would FAIL:
1240
1241             anemometer:
1242               angle: .0
1243
1244       2. With float-values: {forbid-scientific-notation: true}
1245
1246          the following code snippets would PASS:
1247
1248             anemometer:
1249               angle: 0.00001
1250
1251          the following code snippets would FAIL:
1252
1253             anemometer:
1254               angle: 10e-6
1255
1256       3. With float-values: {forbid-nan: true}
1257
1258          the following code snippets would FAIL:
1259
1260             anemometer:
1261               angle: .NaN
1262
1263          1. With float-values: {forbid-inf: true}
1264              the following code snippets would FAIL:
1265
1266                 anemometer:
1267                   angle: .inf
1268
1269   hyphens
1270       Use this rule to control the number of spaces after hyphens (-).
1271
1272       Options
1273
1274max-spaces-after defines the maximal number of spaces  allowed  after
1275         hyphens.
1276
1277       Default values (when enabled)
1278
1279          rules:
1280            hyphens:
1281              max-spaces-after: 1
1282
1283       Examples
1284
1285       1. With hyphens: {max-spaces-after: 1}
1286
1287          the following code snippet would PASS:
1288
1289             - first list:
1290                 - a
1291                 - b
1292             - - 1
1293               - 2
1294               - 3
1295
1296          the following code snippet would FAIL:
1297
1298             -  first list:
1299                  - a
1300                  - b
1301
1302          the following code snippet would FAIL:
1303
1304             - - 1
1305               -  2
1306               - 3
1307
1308       2. With hyphens: {max-spaces-after: 3}
1309
1310          the following code snippet would PASS:
1311
1312             -   key
1313             -  key2
1314             - key42
1315
1316          the following code snippet would FAIL:
1317
1318             -    key
1319             -   key2
1320             -  key42
1321
1322   indentation
1323       Use this rule to control the indentation.
1324
1325       Options
1326
1327spaces defines the indentation width, in spaces. Set either to an in‐
1328         teger (e.g. 2 or 4, representing the number of spaces in an  indenta‐
1329         tion  level)  or to consistent to allow any number, as long as it re‐
1330         mains the same within the file.
1331
1332indent-sequences defines whether block sequences should  be  indented
1333         or  not (when in a mapping, this indentation is not mandatory -- some
1334         people perceive the - as part of the indentation).  Possible  values:
1335         true,  false, whatever and consistent. consistent requires either all
1336         block sequences to be indented, or none to be. whatever means  either
1337         indenting or not indenting individual block sequences is OK.
1338
1339check-multi-line-strings  defines  whether  to  lint  indentation  in
1340         multi-line strings. Set to true to enable, false to disable.
1341
1342       Default values (when enabled)
1343
1344          rules:
1345            indentation:
1346              spaces: consistent
1347              indent-sequences: true
1348              check-multi-line-strings: false
1349
1350       Examples
1351
1352       1. With indentation: {spaces: 1}
1353
1354          the following code snippet would PASS:
1355
1356             history:
1357              - name: Unix
1358                date: 1969
1359              - name: Linux
1360                date: 1991
1361             nest:
1362              recurse:
1363               - haystack:
1364                  needle
1365
1366       2. With indentation: {spaces: 4}
1367
1368          the following code snippet would PASS:
1369
1370             history:
1371                 - name: Unix
1372                   date: 1969
1373                 - name: Linux
1374                   date: 1991
1375             nest:
1376                 recurse:
1377                     - haystack:
1378                           needle
1379
1380          the following code snippet would FAIL:
1381
1382             history:
1383               - name: Unix
1384                 date: 1969
1385               - name: Linux
1386                 date: 1991
1387             nest:
1388               recurse:
1389                 - haystack:
1390                     needle
1391
1392       3. With indentation: {spaces: consistent}
1393
1394          the following code snippet would PASS:
1395
1396             history:
1397                - name: Unix
1398                  date: 1969
1399                - name: Linux
1400                  date: 1991
1401             nest:
1402                recurse:
1403                   - haystack:
1404                        needle
1405
1406          the following code snippet would FAIL:
1407
1408             some:
1409               Russian:
1410                   dolls
1411
1412       4. With indentation: {spaces: 2, indent-sequences: false}
1413
1414          the following code snippet would PASS:
1415
1416             list:
1417             - flying
1418             - spaghetti
1419             - monster
1420
1421          the following code snippet would FAIL:
1422
1423             list:
1424               - flying
1425               - spaghetti
1426               - monster
1427
1428       5. With indentation: {spaces: 2, indent-sequences: whatever}
1429
1430          the following code snippet would PASS:
1431
1432             list:
1433             - flying:
1434               - spaghetti
1435               - monster
1436             - not flying:
1437                 - spaghetti
1438                 - sauce
1439
1440       6. With indentation: {spaces: 2, indent-sequences: consistent}
1441
1442          the following code snippet would PASS:
1443
1444             - flying:
1445               - spaghetti
1446               - monster
1447             - not flying:
1448               - spaghetti
1449               - sauce
1450
1451          the following code snippet would FAIL:
1452
1453             - flying:
1454                 - spaghetti
1455                 - monster
1456             - not flying:
1457               - spaghetti
1458               - sauce
1459
1460       7. With indentation: {spaces: 4, check-multi-line-strings: true}
1461
1462          the following code snippet would PASS:
1463
1464             Blaise Pascal:
1465                 Je vous écris une longue lettre parce que
1466                 je n'ai pas le temps d'en écrire une courte.
1467
1468          the following code snippet would PASS:
1469
1470             Blaise Pascal: Je vous écris une longue lettre parce que
1471                            je n'ai pas le temps d'en écrire une courte.
1472
1473          the following code snippet would FAIL:
1474
1475             Blaise Pascal: Je vous écris une longue lettre parce que
1476               je n'ai pas le temps d'en écrire une courte.
1477
1478          the following code snippet would FAIL:
1479
1480             C code:
1481                 void main() {
1482                     printf("foo");
1483                 }
1484
1485          the following code snippet would PASS:
1486
1487             C code:
1488                 void main() {
1489                 printf("bar");
1490                 }
1491
1492   key-duplicates
1493       Use this rule to prevent multiple entries with the  same  key  in  map‐
1494       pings.
1495
1496       Examples
1497
1498       1. With key-duplicates: {}
1499
1500          the following code snippet would PASS:
1501
1502             - key 1: v
1503               key 2: val
1504               key 3: value
1505             - {a: 1, b: 2, c: 3}
1506
1507          the following code snippet would FAIL:
1508
1509             - key 1: v
1510               key 2: val
1511               key 1: value
1512
1513          the following code snippet would FAIL:
1514
1515             - {a: 1, b: 2, b: 3}
1516
1517          the following code snippet would FAIL:
1518
1519             duplicated key: 1
1520             "duplicated key": 2
1521
1522             other duplication: 1
1523             ? >-
1524                 other
1525                 duplication
1526             : 2
1527
1528   key-ordering
1529       Use this rule to enforce alphabetical ordering of keys in mappings. The
1530       sorting order uses the Unicode code point number as a default. As a re‐
1531       sult, the ordering is case-sensitive and not accent-friendly (see exam‐
1532       ples below).  This can be changed by setting the global locale  option.
1533       This allows one to sort case and accents properly.
1534
1535       Examples
1536
1537       1. With key-ordering: {}
1538
1539          the following code snippet would PASS:
1540
1541             - key 1: v
1542               key 2: val
1543               key 3: value
1544             - {a: 1, b: 2, c: 3}
1545             - T-shirt: 1
1546               T-shirts: 2
1547               t-shirt: 3
1548               t-shirts: 4
1549             - hair: true
1550               hais: true
1551               haïr: true
1552               haïssable: true
1553
1554          the following code snippet would FAIL:
1555
1556             - key 2: v
1557               key 1: val
1558
1559          the following code snippet would FAIL:
1560
1561             - {b: 1, a: 2}
1562
1563          the following code snippet would FAIL:
1564
1565             - T-shirt: 1
1566               t-shirt: 2
1567               T-shirts: 3
1568               t-shirts: 4
1569
1570          the following code snippet would FAIL:
1571
1572             - haïr: true
1573               hais: true
1574
1575       2. With global option locale: "en_US.UTF-8" and rule key-ordering: {}
1576
1577          as opposed to before, the following code snippet would now PASS:
1578
1579             - t-shirt: 1
1580               T-shirt: 2
1581               t-shirts: 3
1582               T-shirts: 4
1583             - hair: true
1584               haïr: true
1585               hais: true
1586               haïssable: true
1587
1588   line-length
1589       Use this rule to set a limit to lines length.
1590
1591       Options
1592
1593max defines the maximal (inclusive) length of lines.
1594
1595allow-non-breakable-words is used to allow non breakable words (with‐
1596         out spaces inside) to overflow the limit. This  is  useful  for  long
1597         URLs, for instance. Use true to allow, false to forbid.
1598
1599allow-non-breakable-inline-mappings implies allow-non-breakable-words
1600         and extends it to also allow non-breakable words in inline mappings.
1601
1602       Default values (when enabled)
1603
1604          rules:
1605            line-length:
1606              max: 80
1607              allow-non-breakable-words: true
1608              allow-non-breakable-inline-mappings: false
1609
1610       Examples
1611
1612       1. With line-length: {max: 70}
1613
1614          the following code snippet would PASS:
1615
1616             long sentence:
1617               Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
1618               eiusmod tempor incididunt ut labore et dolore magna aliqua.
1619
1620          the following code snippet would FAIL:
1621
1622             long sentence:
1623               Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
1624               tempor incididunt ut labore et dolore magna aliqua.
1625
1626       2. With line-length: {max: 60, allow-non-breakable-words: true}
1627
1628          the following code snippet would PASS:
1629
1630             this:
1631               is:
1632                 - a:
1633                     http://localhost/very/very/very/very/very/very/very/very/long/url
1634
1635             # this comment is too long,
1636             # but hard to split:
1637             # http://localhost/another/very/very/very/very/very/very/very/very/long/url
1638
1639          the following code snippet would FAIL:
1640
1641             - this line is waaaaaaaaaaaaaay too long but could be easily split...
1642
1643          and the following code snippet would also FAIL:
1644
1645             - foobar: http://localhost/very/very/very/very/very/very/very/very/long/url
1646
1647       3. With line-length: {max:  60,  allow-non-breakable-words:  true,  al‐
1648          low-non-breakable-inline-mappings: true}
1649
1650          the following code snippet would PASS:
1651
1652             - foobar: http://localhost/very/very/very/very/very/very/very/very/long/url
1653
1654       4. With line-length: {max: 60, allow-non-breakable-words: false}
1655
1656          the following code snippet would FAIL:
1657
1658             this:
1659               is:
1660                 - a:
1661                     http://localhost/very/very/very/very/very/very/very/very/long/url
1662
1663   new-line-at-end-of-file
1664       Use this rule to require a new line character (\n) at the end of files.
1665
1666       The  POSIX standard requires the last line to end with a new line char‐
1667       acter.  All UNIX tools expect a new line at the end of files. Most text
1668       editors use this convention too.
1669
1670   new-lines
1671       Use this rule to force the type of new line characters.
1672
1673       Options
1674
1675       • Set  type to unix to enforce UNIX-typed new line characters (\n), set
1676         type to dos to enforce DOS-typed new line characters (\r\n),  or  set
1677         type  to  platform to infer the type from the system running yamllint
1678         (\n on POSIX / UNIX / Linux / Mac OS systems or \r\n on DOS / Windows
1679         systems).
1680
1681       Default values (when enabled)
1682
1683          rules:
1684            new-lines:
1685              type: unix
1686
1687   octal-values
1688       Use  this  rule  to prevent values with octal numbers. In YAML, numbers
1689       that start with 0 are interpreted as octal,  but  this  is  not  always
1690       wanted.   For  instance 010 is the city code of Beijing, and should not
1691       be converted to 8.
1692
1693       Options
1694
1695       • Use forbid-implicit-octal to prevent numbers starting with 0.
1696
1697       • Use forbid-explicit-octal to prevent numbers starting with 0o.
1698
1699       Default values (when enabled)
1700
1701          rules:
1702            octal-values:
1703              forbid-implicit-octal: true
1704              forbid-explicit-octal: true
1705
1706       Examples
1707
1708       1. With octal-values: {forbid-implicit-octal: true}
1709
1710          the following code snippets would PASS:
1711
1712             user:
1713               city-code: '010'
1714
1715          the following code snippets would PASS:
1716
1717             user:
1718               city-code: 010,021
1719
1720          the following code snippets would FAIL:
1721
1722             user:
1723               city-code: 010
1724
1725       2. With octal-values: {forbid-explicit-octal: true}
1726
1727          the following code snippets would PASS:
1728
1729             user:
1730               city-code: '0o10'
1731
1732          the following code snippets would FAIL:
1733
1734             user:
1735               city-code: 0o10
1736
1737   quoted-strings
1738       Use this rule to forbid any string values that are not  quoted,  or  to
1739       prevent  quoted  strings  without  needing it. You can also enforce the
1740       type of the quote used.
1741
1742       Options
1743
1744quote-type defines allowed quotes: single, double or any (default).
1745
1746required defines whether using quotes in string  values  is  required
1747         (true,  default)  or  not (false), or only allowed when really needed
1748         (only-when-needed).
1749
1750extra-required is a list of PCRE regexes to force string values to be
1751         quoted,  if  they  match any regex. This option can only be used with
1752         required: false and  required: only-when-needed.
1753
1754extra-allowed is a list of PCRE regexes to allow quoted  string  val‐
1755         ues, even if required: only-when-needed is set.
1756
1757allow-quoted-quotes allows (true) using disallowed quotes for strings
1758         with allowed quotes inside. Default false.
1759
1760       Note: Multi-line strings (with | or >) will not be checked.
1761
1762       Default values (when enabled)
1763
1764          rules:
1765            quoted-strings:
1766              quote-type: any
1767              required: true
1768              extra-required: []
1769              extra-allowed: []
1770              allow-quoted-quotes: false
1771
1772       Examples
1773
1774       1. With quoted-strings: {quote-type: any, required: true}
1775
1776          the following code snippet would PASS:
1777
1778             foo: "bar"
1779             bar: 'foo'
1780             number: 123
1781             boolean: true
1782
1783          the following code snippet would FAIL:
1784
1785             foo: bar
1786
1787       2. With     quoted-strings:     {quote-type:     single,      required:
1788          only-when-needed}
1789
1790          the following code snippet would PASS:
1791
1792             foo: bar
1793             bar: foo
1794             not_number: '123'
1795             not_boolean: 'true'
1796             not_comment: '# comment'
1797             not_list: '[1, 2, 3]'
1798             not_map: '{a: 1, b: 2}'
1799
1800          the following code snippet would FAIL:
1801
1802             foo: 'bar'
1803
1804       3. With  quoted-strings:  {required:  false, extra-required: [^http://,
1805          ^ftp://]}
1806
1807          the following code snippet would PASS:
1808
1809             - localhost
1810             - "localhost"
1811             - "http://localhost"
1812             - "ftp://localhost"
1813
1814          the following code snippet would FAIL:
1815
1816             - http://localhost
1817             - ftp://localhost
1818
1819       4. With  quoted-strings:  {required:  only-when-needed,  extra-allowed:
1820          [^http://, ^ftp://], extra-required: [QUOTED]}
1821
1822          the following code snippet would PASS:
1823
1824             - localhost
1825             - "http://localhost"
1826             - "ftp://localhost"
1827             - "this is a string that needs to be QUOTED"
1828
1829          the following code snippet would FAIL:
1830
1831             - "localhost"
1832             - this is a string that needs to be QUOTED
1833
1834       5. With   quoted-strings:   {quote-type:  double,  allow-quoted-quotes:
1835          false}
1836
1837          the following code snippet would PASS:
1838
1839             foo: "bar\"baz"
1840
1841          the following code snippet would FAIL:
1842
1843             foo: 'bar"baz'
1844
1845       6. With quoted-strings: {quote-type: double, allow-quoted-quotes: true}
1846
1847          the following code snippet would PASS:
1848
1849             foo: 'bar"baz'
1850
1851   trailing-spaces
1852       Use this rule to forbid trailing spaces at the end of lines.
1853
1854       Examples
1855
1856       1. With trailing-spaces: {}
1857
1858          the following code snippet would PASS:
1859
1860             this document doesn't contain
1861             any trailing
1862             spaces
1863
1864          the following code snippet would FAIL:
1865
1866             this document contains
1867             trailing spaces
1868             on lines 1 and 3
1869
1870   truthy
1871       Use this rule to forbid non-explicitly typed truthy values  other  than
1872       allowed ones (by default: true and false), for example YES or off.
1873
1874       This  can be useful to prevent surprises from YAML parsers transforming
1875       [yes, FALSE, Off] into [true, false, false] or {y: 1, yes:  2,  on:  3,
1876       true: 4, True: 5} into {y: 1, true: 5}.
1877
1878       Options
1879
1880allowed-values  defines  the  list of truthy values which will be ig‐
1881         nored during linting. The default is ['true', 'false'],  but  can  be
1882         changed  to  any  list  containing: 'TRUE', 'True',  'true', 'FALSE',
1883         'False', 'false', 'YES', 'Yes', 'yes', 'NO', 'No', 'no', 'ON',  'On',
1884         'on', 'OFF', 'Off', 'off'.
1885
1886check-keys  disables  verification  for keys in mappings. By default,
1887         truthy rule applies to both keys and values. Set this option to false
1888         to prevent this.
1889
1890       Default values (when enabled)
1891
1892          rules:
1893            truthy:
1894              allowed-values: ['true', 'false']
1895              check-keys: true
1896
1897       Examples
1898
1899       1. With truthy: {}
1900
1901          the following code snippet would PASS:
1902
1903             boolean: true
1904
1905             object: {"True": 1, 1: "True"}
1906
1907             "yes":  1
1908             "on":   2
1909             "True": 3
1910
1911              explicit:
1912                string1: !!str True
1913                string2: !!str yes
1914                string3: !!str off
1915                encoded: !!binary |
1916                           True
1917                           OFF
1918                           pad==  # this decodes as 'N»ž8Qii'
1919                boolean1: !!bool true
1920                boolean2: !!bool "false"
1921                boolean3: !!bool FALSE
1922                boolean4: !!bool True
1923                boolean5: !!bool off
1924                boolean6: !!bool NO
1925
1926          the following code snippet would FAIL:
1927
1928             object: {True: 1, 1: True}
1929
1930          the following code snippet would FAIL:
1931
1932             yes:  1
1933             on:   2
1934             True: 3
1935
1936       2. With truthy: {allowed-values: ["yes", "no"]}
1937
1938          the following code snippet would PASS:
1939
1940             - yes
1941             - no
1942             - "true"
1943             - 'false'
1944             - foo
1945             - bar
1946
1947          the following code snippet would FAIL:
1948
1949             - true
1950             - false
1951             - on
1952             - off
1953
1954       3. With truthy: {check-keys: false}
1955
1956          the following code snippet would PASS:
1957
1958             yes:  1
1959             on:   2
1960             true: 3
1961
1962          the following code snippet would FAIL:
1963
1964             yes:  Yes
1965             on:   On
1966             true: True
1967
1968   Disable with comments
1969   Disabling checks for a specific line
1970       To  prevent yamllint from reporting problems for a specific line, add a
1971       directive comment (# yamllint disable-line ...) on that line, or on the
1972       line above. For instance:
1973
1974          # The following mapping contains the same key twice,
1975          # but I know what I'm doing:
1976          key: value 1
1977          key: value 2  # yamllint disable-line rule:key-duplicates
1978
1979          - This line is waaaaaaaaaay too long but yamllint will not report anything about it.  # yamllint disable-line rule:line-length
1980            This line will be checked by yamllint.
1981
1982       or:
1983
1984          # The following mapping contains the same key twice,
1985          # but I know what I'm doing:
1986          key: value 1
1987          # yamllint disable-line rule:key-duplicates
1988          key: value 2
1989
1990          # yamllint disable-line rule:line-length
1991          - This line is waaaaaaaaaay too long but yamllint will not report anything about it.
1992            This line will be checked by yamllint.
1993
1994       It  is  possible,  although  not recommend, to disabled all rules for a
1995       specific line:
1996
1997          # yamllint disable-line
1998          -  {    all : rules ,are disabled   for this line}
1999
2000       You can't make yamllint ignore invalid YAML syntax  on  a  line  (which
2001       generates  a  syntax  error),  such as when templating a YAML file with
2002       Jinja. In some cases, you can workaround this by putting the templating
2003       syntax  in  a  YAML  comment. See Putting template flow control in com‐
2004       ments.
2005
2006       If you need to disable multiple rules, it is  allowed  to  chain  rules
2007       like this: # yamllint disable-line rule:hyphens rule:commas rule:inden‐
2008       tation.
2009
2010   Disabling checks for all (or part of) the file
2011       To prevent yamllint from reporting problems for the whole file, or  for
2012       a block of lines within the file, use # yamllint disable ... and # yam‐
2013       llint enable ... directive comments. For instance:
2014
2015          # yamllint disable rule:colons
2016          - Lorem       : ipsum
2017            dolor       : sit amet,
2018            consectetur : adipiscing elit
2019          # yamllint enable rule:colons
2020
2021          - rest of the document...
2022
2023       It is possible, although not recommend, to disabled all rules:
2024
2025          # yamllint disable
2026          - Lorem       :
2027                  ipsum:
2028                    dolor : [   sit,amet]
2029          -         consectetur : adipiscing elit
2030          # yamllint enable
2031
2032       If you need to disable multiple rules, it is  allowed  to  chain  rules
2033       like  this:  #  yamllint disable rule:hyphens rule:commas rule:indenta‐
2034       tion.
2035
2036   Disabling all checks for a file
2037       To prevent yamllint from reporting problems for a  specific  file,  add
2038       the  directive comment # yamllint disable-file as the first line of the
2039       file.  For instance:
2040
2041          # yamllint disable-file
2042          # The following mapping contains the same key twice, but I know what I'm doing:
2043          key: value 1
2044          key: value 2
2045
2046          - This line is waaaaaaaaaay too long but yamllint will not report anything about it.
2047
2048       or:
2049
2050          # yamllint disable-file
2051          # This file is not valid YAML because it is a Jinja template
2052          {% if extra_info %}
2053          key1: value1
2054          {% endif %}
2055          key2: value2
2056
2057   Putting template flow control in comments
2058       Alternatively for templating you can wrap the  template  statements  in
2059       comments  to  make it a valid YAML file. As long as the templating lan‐
2060       guage doesn't use the same comment symbol, it should be  a  valid  tem‐
2061       plate and valid YAML (pre and post-template processing).
2062
2063       Example  of a Jinja2 code that cannot be parsed as YAML because it con‐
2064       tains invalid tokens {% and %}:
2065
2066          # This file IS NOT valid YAML and will produce syntax errors
2067          {% if extra_info %}
2068          key1: value1
2069          {% endif %}
2070          key2: value2
2071
2072       But it can be fixed using YAML comments:
2073
2074          # This file IS valid YAML because the Jinja is in a YAML comment
2075          # {% if extra_info %}
2076          key1: value1
2077          # {% endif %}
2078          key2: value2
2079
2080   Development
2081       yamllint provides both a script and a Python module. The latter can  be
2082       used to write your own linting tools.
2083
2084       Basic example of running the linter from Python:
2085
2086          import yamllint
2087
2088          yaml_config = yamllint.config.YamlLintConfig("extends: default")
2089          for p in yamllint.linter.run(open("example.yaml", "r"), yaml_config):
2090              print(p.desc, p.line, p.rule)
2091
2092       class   yamllint.linter.LintProblem(line,  column,  desc='<no  descrip‐
2093       tion>', rule=None)
2094              Represents a linting problem found by yamllint.
2095
2096              column Column on which the problem was found (starting at 1)
2097
2098              desc   Human-readable description of the problem
2099
2100              line   Line on which the problem was found (starting at 1)
2101
2102              rule   Identifier of the rule that detected the problem
2103
2104       yamllint.linter.run(input, conf, filepath=None)
2105              Lints a YAML source.
2106
2107              Returns a generator of LintProblem objects.
2108
2109              Parameters
2110
2111input -- buffer, string or stream to read from
2112
2113conf -- yamllint configuration object
2114
2115   Integration with text editors
2116       Most text editors support syntax checking and highlighting, to visually
2117       report  syntax errors and warnings to the user. yamllint can be used to
2118       syntax-check YAML source, but a bit of configuration  is  required  de‐
2119       pending on your favorite text editor.
2120
2121   Vim
2122       Assuming that the ALE plugin is installed, yamllint is supported by de‐
2123       fault. It is automatically enabled when editing YAML files.
2124
2125       If you instead use the syntastic plugin, add this to your .vimrc:
2126
2127          let g:syntastic_yaml_checkers = ['yamllint']
2128
2129   Neovim
2130       Assuming that the neomake plugin is installed, yamllint is supported by
2131       default. It is automatically enabled when editing YAML files.
2132
2133   Emacs
2134       If you are flycheck user, you can use flycheck-yamllint integration.
2135
2136   Visual Studio Code
2137       https://marketplace.visualstudio.com/items?itemName=fnando.linter
2138
2139   IntelliJ
2140       https://plugins.jetbrains.com/plugin/15349-yamllint
2141
2142   Other text editors
2143       Help wanted!
2144
2145       Your favorite text editor is not listed here? Help us improve by adding
2146       a section (by opening a pull-request or issue on GitHub).
2147
2148   Integration with other software
2149   Integration with pre-commit
2150       You can integrate yamllint in the pre-commit tool.  Here is an example,
2151       to add in your .pre-commit-config.yaml
2152
2153          ---
2154          # Update the rev variable with the release version that you want, from the yamllint repo
2155          # You can pass your custom .yamllint with args attribute.
2156          repos:
2157            - repo: https://github.com/adrienverge/yamllint.git
2158              rev: v1.29.0
2159              hooks:
2160                - id: yamllint
2161                  args: [--strict, -c=/path/to/.yamllint]
2162
2163   Integration with GitHub Actions
2164       yamllint  auto-detects  when  it's running inside of GitHub Actions and
2165       automatically uses the suited output format to decorate code with lint‐
2166       ing  errors. You can also force the GitHub Actions output with yamllint
2167       --format github.
2168
2169       A minimal example workflow using GitHub Actions:
2170
2171          ---
2172          on: push  # yamllint disable-line rule:truthy
2173
2174          jobs:
2175            lint:
2176              runs-on: ubuntu-latest
2177              steps:
2178                - uses: actions/checkout@v3
2179
2180                - name: Install yamllint
2181                  run: pip install yamllint
2182
2183                - name: Lint YAML files
2184                  run: yamllint .
2185
2186   Integration with Arcanist
2187       You can configure yamllint to run on arc lint. Here is an example  .ar‐
2188       clint file that makes use of this configuration.
2189
2190          {
2191            "linters": {
2192              "yamllint": {
2193                "type": "script-and-regex",
2194                "script-and-regex.script": "yamllint",
2195                "script-and-regex.regex": "/^(?P<line>\\d+):(?P<offset>\\d+) +(?P<severity>warning|error) +(?P<message>.*) +\\((?P<name>.*)\\)$/m",
2196                "include": "(\\.(yml|yaml)$)"
2197              }
2198            }
2199          }
2200

AUTHOR

2202       Adrien Vergé
2203
2205       2023, Adrien Vergé
2206
2207
2208
2209
22101.33.0                           Nov 09, 2023                      YAMLLINT(1)
Impressum