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