1YAMLLINT(1) yamllint YAMLLINT(1)
2
3
4
6 yamllint -
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
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
22 Quickstart
23 Installing yamllint
24 On Fedora / 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 Alternatively using pip, the Python package manager:
37
38 pip install --user yamllint
39
40 If you prefer installing from source, you can run, from the source
41 directory:
42
43 python setup.py sdist
44 pip install --user dist/yamllint-*.tar.gz
45
46 Running yamllint
47 Basic usage:
48
49 yamllint file.yml other-file.yaml
50
51 You can also lint all YAML files in a whole directory:
52
53 yamllint .
54
55 Or lint a YAML stream from standard input:
56
57 echo -e 'this: is\nvalid: YAML' | yamllint -
58
59 The output will look like (colors are not displayed here):
60
61 file.yml
62 1:4 error trailing spaces (trailing-spaces)
63 4:4 error wrong indentation: expected 4 but found 3 (indentation)
64 5:4 error duplication of key "id-00042" in mapping (key-duplicates)
65 6:6 warning comment not indented like content (comments-indentation)
66 12:6 error too many spaces after hyphen (hyphens)
67 15:12 error too many spaces before comma (commas)
68
69 other-file.yaml
70 1:1 warning missing document start "---" (document-start)
71 6:81 error line too long (87 > 80 characters) (line-length)
72 10:1 error too many blank lines (4 > 2) (empty-lines)
73 11:4 error too many spaces inside braces (braces)
74
75 By default, the output of yamllint is colored when run from a terminal,
76 and pure text in other cases. Add the -f standard arguments to force
77 non-colored output. Use the -f colored arguments to force colored out‐
78 put.
79
80 Add the -f parsable arguments if you need an output format parsable by
81 a machine (for instance for syntax highlighting in text editors). The
82 output will then look like:
83
84 file.yml:6:2: [warning] missing starting space in comment (comments)
85 file.yml:57:1: [error] trailing spaces (trailing-spaces)
86 file.yml:60:3: [error] wrong indentation: expected 4 but found 2 (indentation)
87
88 If you have a custom linting configuration file (see how to configure
89 yamllint), it can be passed to yamllint using the -c option:
90
91 yamllint -c ~/myconfig file.yaml
92
93 NOTE:
94 If you have a .yamllint file in your working directory, it will be
95 automatically loaded as configuration by yamllint.
96
97 Configuration
98 yamllint uses a set of rules to check source files for problems. Each
99 rule is independent from the others, and can be enabled, disabled or
100 tweaked. All these settings can be gathered in a configuration file.
101
102 To use a custom configuration file, use the -c option:
103
104 yamllint -c /path/to/myconfig file-to-lint.yaml
105
106 If -c is not provided, yamllint will look for a configuration file in
107 the following locations (by order of preference):
108
109 · .yamllint in the current working directory
110
111 · $XDG_CONFIG_HOME/yamllint/config
112
113 · ~/.config/yamllint/config
114
115 Finally if no config file is found, the default configuration is
116 applied.
117
118 Default configuration
119 Unless told otherwise, yamllint uses its default configuration:
120
121 ---
122
123 rules:
124 braces: enable
125 brackets: enable
126 colons: enable
127 commas: enable
128 comments:
129 level: warning
130 comments-indentation:
131 level: warning
132 document-end: disable
133 document-start:
134 level: warning
135 empty-lines: enable
136 empty-values: enable
137 hyphens: enable
138 indentation: enable
139 key-duplicates: enable
140 key-ordering: disable
141 line-length: enable
142 new-line-at-end-of-file: enable
143 new-lines: enable
144 octal-values: enable
145 quoted-strings: disable
146 trailing-spaces: enable
147 truthy:
148 level: warning
149
150
151 Details on rules can be found on the rules page.
152
153 There is another pre-defined configuration named relaxed. As its name
154 suggests, it is more tolerant:
155
156 ---
157
158 extends: default
159
160 rules:
161 braces:
162 level: warning
163 max-spaces-inside: 1
164 brackets:
165 level: warning
166 max-spaces-inside: 1
167 colons:
168 level: warning
169 commas:
170 level: warning
171 comments: disable
172 comments-indentation: disable
173 document-start: disable
174 empty-lines:
175 level: warning
176 hyphens:
177 level: warning
178 indentation:
179 level: warning
180 indent-sequences: consistent
181 line-length:
182 level: warning
183 allow-non-breakable-inline-mappings: true
184 truthy: disable
185
186
187 It can be chosen using:
188
189 yamllint -d relaxed file.yml
190
191 Extending the default configuration
192 When writing a custom configuration file, you don't need to redefine
193 every rule. Just extend the default configuration (or any
194 already-existing configuration file).
195
196 For instance, if you just want to disable the comments-indentation
197 rule, your file could look like this:
198
199 # This is my first, very own configuration file for yamllint!
200 # It extends the default conf by adjusting some options.
201
202 extends: default
203
204 rules:
205 comments-indentation: disable # don't bother me with this rule
206
207 Similarly, if you want to set the line-length rule as a warning and be
208 less strict on block sequences indentation:
209
210 extends: default
211
212 rules:
213 # 80 chars should be enough, but don't fail if a line is longer
214 line-length:
215 max: 80
216 level: warning
217
218 # accept both key:
219 # - item
220 #
221 # and key:
222 # - item
223 indentation:
224 indent-sequences: whatever
225
226 Custom configuration without a config file
227 It is possible -- although not recommended -- to pass custom configura‐
228 tion options to yamllint with the -d (short for --config-data) option.
229
230 Its content can either be the name of a pre-defined conf (example:
231 default or relaxed) or a serialized YAML object describing the configu‐
232 ration.
233
234 For instance:
235
236 yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" file.yaml
237
238 Errors and warnings
239 Problems detected by yamllint can be raised either as errors or as
240 warnings. The CLI will output them (with different colors when using
241 the colored output format, or auto when run from a terminal).
242
243 By default the script will exit with a return code 1 only when there is
244 one or more error(s).
245
246 However if strict mode is enabled with the -s (or --strict) option, the
247 return code will be:
248
249 · 0 if no errors or warnings occur
250
251 · 1 if one or more errors occur
252
253 · 2 if no errors occur, but one or more warnings occur
254
255 Ignoring paths
256 It is possible to exclude specific files or directories, so that the
257 linter doesn't process them.
258
259 You can either totally ignore files (they won't be looked at):
260
261 extends: default
262
263 ignore: |
264 /this/specific/file.yaml
265 all/this/directory/
266 *.template.yaml
267
268 or ignore paths only for specific rules:
269
270 extends: default
271
272 rules:
273 trailing-spaces:
274 ignore: |
275 /this-file-has-trailing-spaces-but-it-is-OK.yaml
276 /generated/*.yaml
277
278 Note that this .gitignore-style path pattern allows complex path exclu‐
279 sion/inclusion, see the pathspec README file for more details. Here is
280 a more complex example:
281
282 # For all rules
283 ignore: |
284 *.dont-lint-me.yaml
285 /bin/
286 !/bin/*.lint-me-anyway.yaml
287
288 extends: default
289
290 rules:
291 key-duplicates:
292 ignore: |
293 generated
294 *.template.yaml
295 trailing-spaces:
296 ignore: |
297 *.ignore-trailing-spaces.yaml
298 ascii-art/*
299
300 Rules
301 When linting a document with yamllint, a series of rules (such as
302 line-length, trailing-spaces, etc.) are checked against.
303
304 A configuration file can be used to enable or disable these rules, to
305 set their level (error or warning), but also to tweak their options.
306
307 This page describes the rules and their options.
308
309 List of rules
310 · braces
311
312 · brackets
313
314 · colons
315
316 · commas
317
318 · comments
319
320 · comments-indentation
321
322 · document-end
323
324 · document-start
325
326 · empty-lines
327
328 · empty-values
329
330 · hyphens
331
332 · indentation
333
334 · key-duplicates
335
336 · key-ordering
337
338 · line-length
339
340 · new-line-at-end-of-file
341
342 · new-lines
343
344 · octal-values
345
346 · quoted-strings
347
348 · trailing-spaces
349
350 · truthy
351
352 braces
353 Use this rule to control the number of spaces inside braces ({ and }).
354 Options.INDENT 0.0
355
356 · min-spaces-inside defines the minimal number of spaces required
357 inside braces.
358
359 · max-spaces-inside defines the maximal number of spaces allowed inside
360 braces.
361
362 · min-spaces-inside-empty defines the minimal number of spaces required
363 inside empty braces.
364
365 · max-spaces-inside-empty defines the maximal number of spaces allowed
366 inside empty braces.
367Examples.INDENT 0.0
368
369 1. With braces: {min-spaces-inside: 0, max-spaces-inside: 0}
370
371 the following code snippet would PASS:
372
373 object: {key1: 4, key2: 8}
374
375 the following code snippet would FAIL:
376
377 object: { key1: 4, key2: 8 }
378
379 2. With braces: {min-spaces-inside: 1, max-spaces-inside: 3}
380
381 the following code snippet would PASS:
382
383 object: { key1: 4, key2: 8 }
384
385 the following code snippet would PASS:
386
387 object: { key1: 4, key2: 8 }
388
389 the following code snippet would FAIL:
390
391 object: { key1: 4, key2: 8 }
392
393 the following code snippet would FAIL:
394
395 object: {key1: 4, key2: 8 }
396
397 3. With braces: {min-spaces-inside-empty: 0, max-spaces-inside-empty:
398 0}
399
400 the following code snippet would PASS:
401
402 object: {}
403
404 the following code snippet would FAIL:
405
406 object: { }
407
408 4. With braces: {min-spaces-inside-empty: 1, max-spaces-inside-empty:
409 -1}
410
411 the following code snippet would PASS:
412
413 object: { }
414
415 the following code snippet would FAIL:
416
417 object: {}
418
419 brackets
420 Use this rule to control the number of spaces inside brackets ([ and
421 ]). Options.INDENT 0.0
422
423 · min-spaces-inside defines the minimal number of spaces required
424 inside brackets.
425
426 · max-spaces-inside defines the maximal number of spaces allowed inside
427 brackets.
428
429 · min-spaces-inside-empty defines the minimal number of spaces required
430 inside empty brackets.
431
432 · max-spaces-inside-empty defines the maximal number of spaces allowed
433 inside empty brackets.
434Examples.INDENT 0.0
435
436 1. With brackets: {min-spaces-inside: 0, max-spaces-inside: 0}
437
438 the following code snippet would PASS:
439
440 object: [1, 2, abc]
441
442 the following code snippet would FAIL:
443
444 object: [ 1, 2, abc ]
445
446 2. With brackets: {min-spaces-inside: 1, max-spaces-inside: 3}
447
448 the following code snippet would PASS:
449
450 object: [ 1, 2, abc ]
451
452 the following code snippet would PASS:
453
454 object: [ 1, 2, abc ]
455
456 the following code snippet would FAIL:
457
458 object: [ 1, 2, abc ]
459
460 the following code snippet would FAIL:
461
462 object: [1, 2, abc ]
463
464 3. With brackets: {min-spaces-inside-empty: 0, max-spaces-inside-empty:
465 0}
466
467 the following code snippet would PASS:
468
469 object: []
470
471 the following code snippet would FAIL:
472
473 object: [ ]
474
475 4. With brackets: {min-spaces-inside-empty: 1, max-spaces-inside-empty:
476 -1}
477
478 the following code snippet would PASS:
479
480 object: [ ]
481
482 the following code snippet would FAIL:
483
484 object: []
485
486 colons
487 Use this rule to control the number of spaces before and after colons
488 (:). Options.INDENT 0.0
489
490 · max-spaces-before defines the maximal number of spaces allowed before
491 colons (use -1 to disable).
492
493 · max-spaces-after defines the maximal number of spaces allowed after
494 colons (use -1 to disable).
495Examples.INDENT 0.0
496
497 1. With colons: {max-spaces-before: 0, max-spaces-after: 1}
498
499 the following code snippet would PASS:
500
501 object:
502 - a
503 - b
504 key: value
505
506 2. With colons: {max-spaces-before: 1}
507
508 the following code snippet would PASS:
509
510 object :
511 - a
512 - b
513
514 the following code snippet would FAIL:
515
516 object :
517 - a
518 - b
519
520 3. With colons: {max-spaces-after: 2}
521
522 the following code snippet would PASS:
523
524 first: 1
525 second: 2
526 third: 3
527
528 the following code snippet would FAIL:
529
530 first: 1
531 2nd: 2
532 third: 3
533
534 commas
535 Use this rule to control the number of spaces before and after commas
536 (,). Options.INDENT 0.0
537
538 · max-spaces-before defines the maximal number of spaces allowed before
539 commas (use -1 to disable).
540
541 · min-spaces-after defines the minimal number of spaces required after
542 commas.
543
544 · max-spaces-after defines the maximal number of spaces allowed after
545 commas (use -1 to disable).
546Examples.INDENT 0.0
547
548 1. With commas: {max-spaces-before: 0}
549
550 the following code snippet would PASS:
551
552 strange var:
553 [10, 20, 30, {x: 1, y: 2}]
554
555 the following code snippet would FAIL:
556
557 strange var:
558 [10, 20 , 30, {x: 1, y: 2}]
559
560 2. With commas: {max-spaces-before: 2}
561
562 the following code snippet would PASS:
563
564 strange var:
565 [10 , 20 , 30, {x: 1 , y: 2}]
566
567 3. With commas: {max-spaces-before: -1}
568
569 the following code snippet would PASS:
570
571 strange var:
572 [10,
573 20 , 30
574 , {x: 1, y: 2}]
575
576 4. With commas: {min-spaces-after: 1, max-spaces-after: 1}
577
578 the following code snippet would PASS:
579
580 strange var:
581 [10, 20,30, {x: 1, y: 2}]
582
583 the following code snippet would FAIL:
584
585 strange var:
586 [10, 20,30, {x: 1, y: 2}]
587
588 5. With commas: {min-spaces-after: 1, max-spaces-after: 3}
589
590 the following code snippet would PASS:
591
592 strange var:
593 [10, 20, 30, {x: 1, y: 2}]
594
595 6. With commas: {min-spaces-after: 0, max-spaces-after: 1}
596
597 the following code snippet would PASS:
598
599 strange var:
600 [10, 20,30, {x: 1, y: 2}]
601
602 comments
603 Use this rule to control the position and formatting of comments.
604 Options.INDENT 0.0
605
606 · Use require-starting-space to require a space character right after
607 the #. Set to true to enable, false to disable.
608
609 · Use ignore-shebangs to ignore a shebang at the beginning of the file
610 when require-starting-space is set.
611
612 · min-spaces-from-content is used to visually separate inline comments
613 from content. It defines the minimal required number of spaces
614 between a comment and its preceding content.
615Examples.INDENT 0.0
616
617 1. With comments: {require-starting-space: true}
618
619 the following code snippet would PASS:
620
621 # This sentence
622 # is a block comment
623
624 the following code snippet would PASS:
625
626 ##############################
627 ## This is some documentation
628
629 the following code snippet would FAIL:
630
631 #This sentence
632 #is a block comment
633
634 2. With comments: {min-spaces-from-content: 2}
635
636 the following code snippet would PASS:
637
638 x = 2 ^ 127 - 1 # Mersenne prime number
639
640 the following code snippet would FAIL:
641
642 x = 2 ^ 127 - 1 # Mersenne prime number
643
644 comments-indentation
645 Use this rule to force comments to be indented like content. Exam‐
646 ples.INDENT 0.0
647
648 1. With comments-indentation: {}
649
650 the following code snippet would PASS:
651
652 # Fibonacci
653 [0, 1, 1, 2, 3, 5]
654
655 the following code snippet would FAIL:
656
657 # Fibonacci
658 [0, 1, 1, 2, 3, 5]
659
660 the following code snippet would PASS:
661
662 list:
663 - 2
664 - 3
665 # - 4
666 - 5
667
668 the following code snippet would FAIL:
669
670 list:
671 - 2
672 - 3
673 # - 4
674 - 5
675
676 the following code snippet would PASS:
677
678 # This is the first object
679 obj1:
680 - item A
681 # - item B
682 # This is the second object
683 obj2: []
684
685 the following code snippet would PASS:
686
687 # This sentence
688 # is a block comment
689
690 the following code snippet would FAIL:
691
692 # This sentence
693 # is a block comment
694
695 document-end
696 Use this rule to require or forbid the use of document end marker
697 (...). Options.INDENT 0.0
698
699 · Set present to true when the document end marker is required, or to
700 false when it is forbidden.
701Examples.INDENT 0.0
702
703 1. With document-end: {present: true}
704
705 the following code snippet would PASS:
706
707 ---
708 this:
709 is: [a, document]
710 ...
711 ---
712 - this
713 - is: another one
714 ...
715
716 the following code snippet would FAIL:
717
718 ---
719 this:
720 is: [a, document]
721 ---
722 - this
723 - is: another one
724 ...
725
726 2. With document-end: {present: false}
727
728 the following code snippet would PASS:
729
730 ---
731 this:
732 is: [a, document]
733 ---
734 - this
735 - is: another one
736
737 the following code snippet would FAIL:
738
739 ---
740 this:
741 is: [a, document]
742 ...
743 ---
744 - this
745 - is: another one
746
747 document-start
748 Use this rule to require or forbid the use of document start marker
749 (---). Options.INDENT 0.0
750
751 · Set present to true when the document start marker is required, or to
752 false when it is forbidden.
753Examples.INDENT 0.0
754
755 1. With document-start: {present: true}
756
757 the following code snippet would PASS:
758
759 ---
760 this:
761 is: [a, document]
762 ---
763 - this
764 - is: another one
765
766 the following code snippet would FAIL:
767
768 this:
769 is: [a, document]
770 ---
771 - this
772 - is: another one
773
774 2. With document-start: {present: false}
775
776 the following code snippet would PASS:
777
778 this:
779 is: [a, document]
780 ...
781
782 the following code snippet would FAIL:
783
784 ---
785 this:
786 is: [a, document]
787 ...
788
789 empty-lines
790 Use this rule to set a maximal number of allowed consecutive blank
791 lines. Options.INDENT 0.0
792
793 · max defines the maximal number of empty lines allowed in the docu‐
794 ment.
795
796 · max-start defines the maximal number of empty lines allowed at the
797 beginning of the file. This option takes precedence over max.
798
799 · max-end defines the maximal number of empty lines allowed at the end
800 of the file. This option takes precedence over max.
801Examples.INDENT 0.0
802
803 1. With empty-lines: {max: 1}
804
805 the following code snippet would PASS:
806
807 - foo:
808 - 1
809 - 2
810
811 - bar: [3, 4]
812
813 the following code snippet would FAIL:
814
815 - foo:
816 - 1
817 - 2
818
819
820 - bar: [3, 4]
821
822 empty-values
823 Use this rule to prevent nodes with empty content, that implicitly
824 result in null values. Options.INDENT 0.0
825
826 · Use forbid-in-block-mappings to prevent empty values in block map‐
827 pings.
828
829 · Use forbid-in-flow-mappings to prevent empty values in flow mappings.
830Examples.INDENT 0.0
831
832 1. With empty-values: {forbid-in-block-mappings: true}
833
834 the following code snippets would PASS:
835
836 some-mapping:
837 sub-element: correctly indented
838
839 explicitly-null: null
840
841 the following code snippets would FAIL:
842
843 some-mapping:
844 sub-element: incorrectly indented
845
846 implicitly-null:
847
848 2. With empty-values: {forbid-in-flow-mappings: true}
849
850 the following code snippet would PASS:
851
852 {prop: null}
853 {a: 1, b: 2, c: 3}
854
855 the following code snippets would FAIL:
856
857 {prop: }
858
859 {a: 1, b:, c: 3}
860
861 hyphens
862 Use this rule to control the number of spaces after hyphens (-).
863 Options.INDENT 0.0
864
865 · max-spaces-after defines the maximal number of spaces allowed after
866 hyphens.
867Examples.INDENT 0.0
868
869 1. With hyphens: {max-spaces-after: 1}
870
871 the following code snippet would PASS:
872
873 - first list:
874 - a
875 - b
876 - - 1
877 - 2
878 - 3
879
880 the following code snippet would FAIL:
881
882 - first list:
883 - a
884 - b
885
886 the following code snippet would FAIL:
887
888 - - 1
889 - 2
890 - 3
891
892 2. With hyphens: {max-spaces-after: 3}
893
894 the following code snippet would PASS:
895
896 - key
897 - key2
898 - key42
899
900 the following code snippet would FAIL:
901
902 - key
903 - key2
904 - key42
905
906 indentation
907 Use this rule to control the indentation. Options.INDENT 0.0
908
909 · spaces defines the indentation width, in spaces. Set either to an
910 integer (e.g. 2 or 4, representing the number of spaces in an inden‐
911 tation level) or to consistent to allow any number, as long as it
912 remains the same within the file.
913
914 · indent-sequences defines whether block sequences should be indented
915 or not (when in a mapping, this indentation is not mandatory -- some
916 people perceive the - as part of the indentation). Possible values:
917 true, false, whatever and consistent. consistent requires either all
918 block sequences to be indented, or none to be. whatever means either
919 indenting or not indenting individual block sequences is OK.
920
921 · check-multi-line-strings defines whether to lint indentation in
922 multi-line strings. Set to true to enable, false to disable.
923Examples.INDENT 0.0
924
925 1. With indentation: {spaces: 1}
926
927 the following code snippet would PASS:
928
929 history:
930 - name: Unix
931 date: 1969
932 - name: Linux
933 date: 1991
934 nest:
935 recurse:
936 - haystack:
937 needle
938
939 2. With indentation: {spaces: 4}
940
941 the following code snippet would PASS:
942
943 history:
944 - name: Unix
945 date: 1969
946 - name: Linux
947 date: 1991
948 nest:
949 recurse:
950 - haystack:
951 needle
952
953 the following code snippet would FAIL:
954
955 history:
956 - name: Unix
957 date: 1969
958 - name: Linux
959 date: 1991
960 nest:
961 recurse:
962 - haystack:
963 needle
964
965 3. With indentation: {spaces: consistent}
966
967 the following code snippet would PASS:
968
969 history:
970 - name: Unix
971 date: 1969
972 - name: Linux
973 date: 1991
974 nest:
975 recurse:
976 - haystack:
977 needle
978
979 the following code snippet would FAIL:
980
981 some:
982 Russian:
983 dolls
984
985 4. With indentation: {spaces: 2, indent-sequences: false}
986
987 the following code snippet would PASS:
988
989 list:
990 - flying
991 - spaghetti
992 - monster
993
994 the following code snippet would FAIL:
995
996 list:
997 - flying
998 - spaghetti
999 - monster
1000
1001 5. With indentation: {spaces: 2, indent-sequences: whatever}
1002
1003 the following code snippet would PASS:
1004
1005 list:
1006 - flying:
1007 - spaghetti
1008 - monster
1009 - not flying:
1010 - spaghetti
1011 - sauce
1012
1013 6. With indentation: {spaces: 2, indent-sequences: consistent}
1014
1015 the following code snippet would PASS:
1016
1017 - flying:
1018 - spaghetti
1019 - monster
1020 - not flying:
1021 - spaghetti
1022 - sauce
1023
1024 the following code snippet would FAIL:
1025
1026 - flying:
1027 - spaghetti
1028 - monster
1029 - not flying:
1030 - spaghetti
1031 - sauce
1032
1033 7. With indentation: {spaces: 4, check-multi-line-strings: true}
1034
1035 the following code snippet would PASS:
1036
1037 Blaise Pascal:
1038 Je vous écris une longue lettre parce que
1039 je n'ai pas le temps d'en écrire une courte.
1040
1041 the following code snippet would PASS:
1042
1043 Blaise Pascal: Je vous écris une longue lettre parce que
1044 je n'ai pas le temps d'en écrire une courte.
1045
1046 the following code snippet would FAIL:
1047
1048 Blaise Pascal: Je vous écris une longue lettre parce que
1049 je n'ai pas le temps d'en écrire une courte.
1050
1051 the following code snippet would FAIL:
1052
1053 C code:
1054 void main() {
1055 printf("foo");
1056 }
1057
1058 the following code snippet would PASS:
1059
1060 C code:
1061 void main() {
1062 printf("bar");
1063 }
1064
1065 key-duplicates
1066 Use this rule to prevent multiple entries with the same key in map‐
1067 pings. Examples.INDENT 0.0
1068
1069 1. With key-duplicates: {}
1070
1071 the following code snippet would PASS:
1072
1073 - key 1: v
1074 key 2: val
1075 key 3: value
1076 - {a: 1, b: 2, c: 3}
1077
1078 the following code snippet would FAIL:
1079
1080 - key 1: v
1081 key 2: val
1082 key 1: value
1083
1084 the following code snippet would FAIL:
1085
1086 - {a: 1, b: 2, b: 3}
1087
1088 the following code snippet would FAIL:
1089
1090 duplicated key: 1
1091 "duplicated key": 2
1092
1093 other duplication: 1
1094 ? >-
1095 other
1096 duplication
1097 : 2
1098
1099 key-ordering
1100 Use this rule to enforce alphabetical ordering of keys in mappings. The
1101 sorting order uses the Unicode code point number. As a result, the
1102 ordering is case-sensitive and not accent-friendly (see examples
1103 below). Examples.INDENT 0.0
1104
1105 1. With key-ordering: {}
1106
1107 the following code snippet would PASS:
1108
1109 - key 1: v
1110 key 2: val
1111 key 3: value
1112 - {a: 1, b: 2, c: 3}
1113 - T-shirt: 1
1114 T-shirts: 2
1115 t-shirt: 3
1116 t-shirts: 4
1117 - hair: true
1118 hais: true
1119 haïr: true
1120 haïssable: true
1121
1122 the following code snippet would FAIL:
1123
1124 - key 2: v
1125 key 1: val
1126
1127 the following code snippet would FAIL:
1128
1129 - {b: 1, a: 2}
1130
1131 the following code snippet would FAIL:
1132
1133 - T-shirt: 1
1134 t-shirt: 2
1135 T-shirts: 3
1136 t-shirts: 4
1137
1138 the following code snippet would FAIL:
1139
1140 - haïr: true
1141 hais: true
1142
1143 line-length
1144 Use this rule to set a limit to lines length.
1145
1146 Note: with Python 2, the line-length rule may not work properly with
1147 unicode characters because of the way strings are represented in bytes.
1148 We recommend running yamllint with Python 3. Options.INDENT 0.0
1149
1150 · max defines the maximal (inclusive) length of lines.
1151
1152 · allow-non-breakable-words is used to allow non breakable words (with‐
1153 out spaces inside) to overflow the limit. This is useful for long
1154 URLs, for instance. Use true to allow, false to forbid.
1155
1156 · allow-non-breakable-inline-mappings implies allow-non-breakable-words
1157 and extends it to also allow non-breakable words in inline mappings.
1158Examples.INDENT 0.0
1159
1160 1. With line-length: {max: 70}
1161
1162 the following code snippet would PASS:
1163
1164 long sentence:
1165 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
1166 eiusmod tempor incididunt ut labore et dolore magna aliqua.
1167
1168 the following code snippet would FAIL:
1169
1170 long sentence:
1171 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
1172 tempor incididunt ut labore et dolore magna aliqua.
1173
1174 2. With line-length: {max: 60, allow-non-breakable-words: true}
1175
1176 the following code snippet would PASS:
1177
1178 this:
1179 is:
1180 - a:
1181 http://localhost/very/very/very/very/very/very/very/very/long/url
1182
1183 # this comment is too long,
1184 # but hard to split:
1185 # http://localhost/another/very/very/very/very/very/very/very/very/long/url
1186
1187 the following code snippet would FAIL:
1188
1189 - this line is waaaaaaaaaaaaaay too long but could be easily split...
1190
1191 and the following code snippet would also FAIL:
1192
1193 - foobar: http://localhost/very/very/very/very/very/very/very/very/long/url
1194
1195 3. With line-length: {max: 60, allow-non-breakable-words: true,
1196 allow-non-breakable-inline-mappings: true}
1197
1198 the following code snippet would PASS:
1199
1200 - foobar: http://localhost/very/very/very/very/very/very/very/very/long/url
1201
1202 4. With line-length: {max: 60, allow-non-breakable-words: false}
1203
1204 the following code snippet would FAIL:
1205
1206 this:
1207 is:
1208 - a:
1209 http://localhost/very/very/very/very/very/very/very/very/long/url
1210
1211 new-line-at-end-of-file
1212 Use this rule to require a new line character (\n) at the end of files.
1213
1214 The POSIX standard requires the last line to end with a new line char‐
1215 acter. All UNIX tools expect a new line at the end of files. Most text
1216 editors use this convention too.
1217
1218 new-lines
1219 Use this rule to force the type of new line characters. Options.INDENT
1220 0.0
1221
1222 · Set type to unix to use UNIX-typed new line characters (\n), or dos
1223 to use DOS-typed new line characters (\r\n).
1224
1225 octal-values
1226 Use this rule to prevent values with octal numbers. In YAML, numbers
1227 that start with 0 are interpreted as octal, but this is not always
1228 wanted. For instance 010 is the city code of Beijing, and should not
1229 be converted to 8. Examples.INDENT 0.0
1230
1231 1. With octal-values: {forbid-implicit-octal: true}
1232
1233 the following code snippets would PASS:
1234
1235 user:
1236 city-code: '010'
1237
1238 the following code snippets would PASS:
1239
1240 user:
1241 city-code: 010,021
1242
1243 the following code snippets would FAIL:
1244
1245 user:
1246 city-code: 010
1247
1248 2. With octal-values: {forbid-explicit-octal: true}
1249
1250 the following code snippets would PASS:
1251
1252 user:
1253 city-code: '0o10'
1254
1255 the following code snippets would FAIL:
1256
1257 user:
1258 city-code: 0o10
1259
1260 quoted-strings
1261 Use this rule to forbid any string values that are not quoted. You can
1262 also enforce the type of the quote used using the quote-type option
1263 (single, double or any).
1264
1265 Note: Multi-line strings (with | or >) will not be checked. Exam‐
1266 ples.INDENT 0.0
1267
1268 1. With quoted-strings: {quote-type: any}
1269
1270 the following code snippet would PASS:
1271
1272 foo: "bar"
1273 bar: 'foo'
1274 number: 123
1275 boolean: true
1276
1277 the following code snippet would FAIL:
1278
1279 foo: bar
1280
1281 trailing-spaces
1282 Use this rule to forbid trailing spaces at the end of lines. Exam‐
1283 ples.INDENT 0.0
1284
1285 1. With trailing-spaces: {}
1286
1287 the following code snippet would PASS:
1288
1289 this document doesn't contain
1290 any trailing
1291 spaces
1292
1293 the following code snippet would FAIL:
1294
1295 this document contains
1296 trailing spaces
1297 on lines 1 and 3
1298
1299 truthy
1300 Use this rule to forbid non-explictly typed truthy values other than
1301 allowed ones (by default: true and false), for example YES or off.
1302
1303 This can be useful to prevent surprises from YAML parsers transforming
1304 [yes, FALSE, Off] into [true, false, false] or {y: 1, yes: 2, on: 3,
1305 true: 4, True: 5} into {y: 1, true: 5}. Options.INDENT 0.0
1306
1307 · allowed-values defines the list of truthy values which will be
1308 ignored during linting. The default is ['true', 'false'], but can be
1309 changed to any list containing: 'TRUE', 'True', 'true', 'FALSE',
1310 'False', 'false', 'YES', 'Yes', 'yes', 'NO', 'No', 'no', 'ON', 'On',
1311 'on', 'OFF', 'Off', 'off'.
1312Examples.INDENT 0.0
1313
1314 1. With truthy: {}
1315
1316 the following code snippet would PASS:
1317
1318 boolean: true
1319
1320 object: {"True": 1, 1: "True"}
1321
1322 "yes": 1
1323 "on": 2
1324 "True": 3
1325
1326 explicit:
1327 string1: !!str True
1328 string2: !!str yes
1329 string3: !!str off
1330 encoded: !!binary |
1331 True
1332 OFF
1333 pad== # this decodes as 'N»8Qii'
1334 boolean1: !!bool true
1335 boolean2: !!bool "false"
1336 boolean3: !!bool FALSE
1337 boolean4: !!bool True
1338 boolean5: !!bool off
1339 boolean6: !!bool NO
1340
1341 the following code snippet would FAIL:
1342
1343 object: {True: 1, 1: True}
1344
1345 the following code snippet would FAIL:
1346
1347 yes: 1
1348 on: 2
1349 True: 3
1350
1351 2. With truthy: {allowed-values: ["yes", "no"]}
1352
1353 the following code snippet would PASS:
1354
1355 - yes
1356 - no
1357 - "true"
1358 - 'false'
1359 - foo
1360 - bar
1361
1362 the following code snippet would FAIL:
1363
1364 - true
1365 - false
1366 - on
1367 - off
1368
1369 Disable with comments
1370 Disabling checks for a specific line
1371 To prevent yamllint from reporting problems for a specific line, add a
1372 directive comment (# yamllint disable-line ...) on that line, or on the
1373 line above. For instance:
1374
1375 # The following mapping contains the same key twice,
1376 # but I know what I'm doing:
1377 key: value 1
1378 key: value 2 # yamllint disable-line rule:key-duplicates
1379
1380 - This line is waaaaaaaaaay too long but yamllint will not report anything about it. # yamllint disable-line rule:line-length
1381 This line will be checked by yamllint.
1382
1383 or:
1384
1385 # The following mapping contains the same key twice,
1386 # but I know what I'm doing:
1387 key: value 1
1388 # yamllint disable-line rule:key-duplicates
1389 key: value 2
1390
1391 # yamllint disable-line rule:line-length
1392 - This line is waaaaaaaaaay too long but yamllint will not report anything about it.
1393 This line will be checked by yamllint.
1394
1395 It is possible, although not recommend, to disabled all rules for a
1396 specific line:
1397
1398 # yamllint disable-line
1399 - { all : rules ,are disabled for this line}
1400
1401 If you need to disable multiple rules, it is allowed to chain rules
1402 like this: # yamllint disable-line rule:hyphens rule:commas rule:inden‐
1403 tation.
1404
1405 Disabling checks for all (or part of) the file
1406 To prevent yamllint from reporting problems for the whole file, or for
1407 a block of lines within the file, use # yamllint disable ... and # yam‐
1408 llint enable ... directive comments. For instance:
1409
1410 # yamllint disable rule:colons
1411 - Lorem : ipsum
1412 dolor : sit amet,
1413 consectetur : adipiscing elit
1414 # yamllint enable rule:colons
1415
1416 - rest of the document...
1417
1418 It is possible, although not recommend, to disabled all rules:
1419
1420 # yamllint disable
1421 - Lorem :
1422 ipsum:
1423 dolor : [ sit,amet]
1424 - consectetur : adipiscing elit
1425 # yamllint enable
1426
1427 If you need to disable multiple rules, it is allowed to chain rules
1428 like this: # yamllint disable rule:hyphens rule:commas rule:indenta‐
1429 tion.
1430
1431 Development
1432 yamllint provides both a script and a Python module. The latter can be
1433 used to write your own linting tools:
1434
1435 class yamllint.linter.LintProblem(line, column, desc='<no descrip‐
1436 tion>', rule=None)
1437 Represents a linting problem found by yamllint.
1438
1439 column = None
1440 Column on which the problem was found (starting at 1)
1441
1442 desc = None
1443 Human-readable description of the problem
1444
1445 line = None
1446 Line on which the problem was found (starting at 1)
1447
1448 rule = None
1449 Identifier of the rule that detected the problem
1450
1451 yamllint.linter.run(input, conf, filepath=None)
1452 Lints a YAML source.
1453
1454 Returns a generator of LintProblem objects.
1455
1456 Parameters
1457
1458 · input -- buffer, string or stream to read from
1459
1460 · conf -- yamllint configuration object
1461
1462 Integration with text editors
1463 Most text editors support syntax checking and highlighting, to visually
1464 report syntax errors and warnings to the user. yamllint can be used to
1465 syntax-check YAML source, but a bit of configuration is required
1466 depending on your favorite text editor.
1467
1468 Vim
1469 Assuming that the ALE plugin is installed, yamllint is supported by
1470 default. It is automatically enabled when editing YAML files.
1471
1472 If you instead use the syntastic plugin, add this to your .vimrc:
1473
1474 let g:syntastic_yaml_checkers = ['yamllint']
1475
1476 Neovim
1477 Assuming that the neomake plugin is installed, yamllint is supported by
1478 default. It is automatically enabled when editing YAML files.
1479
1480 Emacs
1481 If you are flycheck user, you can use flycheck-yamllint integration.
1482
1483 Other text editors
1484 Help wanted!
1485
1486 Your favorite text editor is not listed here? Help us improve by adding
1487 a section (by opening a pull-request or issue on GitHub).
1488
1489 Integration with other software
1490 Integration with pre-commit
1491 You can integrate yamllint in pre-commit tool. Here is an example, to
1492 add in your .pre-commit-config.yaml
1493
1494 ---
1495 # Update the sha variable with the release version that you want, from the yamllint repo
1496 - repo: https://github.com/adrienverge/yamllint.git
1497 sha: v1.8.1
1498 hooks:
1499 - id: yamllint
1500
1502 Adrien Vergé
1503
1505 Copyright 2016, Adrien Vergé
1506
1507
1508
1509
15101.16.0 Jun 07, 2019 YAMLLINT(1)