Skip to content

Commit ab5b292

Browse files
committed
Incorporate yamllint for checking YAML documents
Signed-off-by: 林博仁(Buo-ren Lin) <Buo.Ren.Lin@gmail.com>
1 parent 880c6ab commit ab5b292

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed

.yamllint

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
%YAML 1.2
2+
---
3+
# Configuration File of yamllint
4+
# https://yamllint.readthedocs.io
5+
#
6+
# This file is in YAML Ain’t Markup Language (YAML™)
7+
# http://yaml.org/
8+
#
9+
# This file is based on the `default` pre-defined configuration from yamllint with documentation copied from its documentation
10+
# https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration
11+
#
12+
# This file is based on The Unofficial yamllint Configuration Templates
13+
# https://github.com/Lin-Buo-Ren/yamllint-configuration-templates
14+
#
15+
# SPDX-License-Identifier: CC-BY-SA-4.0
16+
# Copyright © 2020 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
17+
rules:
18+
# Use this rule to control the number of spaces inside braces (`{` and `}`).
19+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.braces
20+
braces:
21+
min-spaces-inside: 0
22+
max-spaces-inside: 0
23+
min-spaces-inside-empty: -1
24+
max-spaces-inside-empty: -1
25+
26+
# Use this rule to control the number of spaces inside brackets (`[` and `]`).
27+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.brackets
28+
brackets:
29+
min-spaces-inside: 0
30+
max-spaces-inside: 0
31+
min-spaces-inside-empty: -1
32+
max-spaces-inside-empty: -1
33+
34+
# Use this rule to control the number of spaces before and after colons (`:`).
35+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.colons
36+
colons:
37+
max-spaces-before: 0
38+
max-spaces-after: 1
39+
40+
# Use this rule to control the number of spaces before and after commas (`,`).
41+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.commas
42+
commas:
43+
max-spaces-before: 0
44+
min-spaces-after: 1
45+
max-spaces-after: 1
46+
47+
# Use this rule to control the position and formatting of comments.
48+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.comments
49+
comments:
50+
level: warning
51+
# PATCHED: Comments without separate space are disabled content
52+
require-starting-space: false
53+
# PATCHED: We're good with 1
54+
min-spaces-from-content: 1
55+
56+
# Use this rule to force comments to be indented like content.
57+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.comments_indentation
58+
# PATCHED: False positives, disabled
59+
comments-indentation: disable
60+
#level: warning
61+
62+
# Use this rule to require or forbid the use of document end marker (`...`).
63+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.document_end
64+
document-end: disable
65+
66+
# Use this rule to require or forbid the use of document start marker (`---`).
67+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.document_start
68+
# PATCHED: Some config allows, while some config rejects document start markers
69+
document-start: disable
70+
#level: warning
71+
#present: true
72+
73+
# Use this rule to set a maximal number of allowed consecutive blank lines.
74+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.empty_lines
75+
empty-lines:
76+
max: 2
77+
max-start: 0
78+
max-end: 0
79+
80+
# Use this rule to prevent nodes with empty content, that implicitly result in null values.
81+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.empty_values
82+
empty-values:
83+
forbid-in-block-mappings: false
84+
forbid-in-flow-mappings: false
85+
86+
# Use this rule to control the number of spaces after hyphens (`-`).
87+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.hyphens
88+
hyphens:
89+
max-spaces-after: 1
90+
91+
# Use this rule to control the indentation.
92+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.indentation
93+
indentation:
94+
spaces: consistent
95+
indent-sequences: true
96+
check-multi-line-strings: false
97+
98+
# Use this rule to prevent multiple entries with the same key in mappings.
99+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.key_duplicates
100+
key-duplicates: enable
101+
102+
# Use this rule to enforce alphabetical ordering of keys in mappings. The sorting order uses the Unicode code point number. As a result, the ordering is case-sensitive and not accent-friendly (see examples below).
103+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.key_ordering
104+
key-ordering: disable
105+
106+
# Use this rule to set a limit to lines length.
107+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.line_length
108+
line-length:
109+
# PATCHED: Modern text editors handle long lines nicely
110+
max: 99999
111+
allow-non-breakable-words: true
112+
allow-non-breakable-inline-mappings: false
113+
114+
# Use this rule to require a new line character (`\n`) at the end of files.
115+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.new_line_at_end_of_file
116+
new-line-at-end-of-file: enable
117+
118+
# Use this rule to force the type of new line characters.
119+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.new_lines
120+
new-lines:
121+
type: unix
122+
123+
# Use this rule to prevent values with octal numbers. In YAML, numbers that start with `0` are interpreted as octal, but this is not always wanted. For instance `010` is the city code of Beijing, and should not be converted to `8`.
124+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.octal_values
125+
octal-values:
126+
forbid-implicit-octal: false
127+
forbid-explicit-octal: false
128+
129+
# Use this rule to forbid trailing spaces at the end of lines.
130+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.trailing_spaces
131+
trailing-spaces: enable
132+
133+
# Use this rule to forbid non-explictly typed truthy values other than `true` and `false`, for example `YES`, `False` and `off`.
134+
# https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.truthy
135+
truthy:
136+
level: warning
137+
...

common.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ repos:
5454
rev: v0.12.1
5555
hooks:
5656
- id: reuse
57+
58+
# Check YAML files
59+
# https://github.com/adrienverge/yamllint
60+
- repo: https://github.com/adrienverge/yamllint
61+
rev: v1.26.1
62+
hooks:
63+
- id: yamllint

0 commit comments

Comments
 (0)