Skip to content

Commit 9d3681c

Browse files
fabiobaltiericarlescufi
authored andcommitted
scripts: compliance: add support for YAMLLint
Add a YAMLLint compliance check that uses the yamllint package to report linting error on YAML files. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 888607d commit 9d3681c

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

.github/workflows/compliance.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: |
2828
pip3 install setuptools
2929
pip3 install wheel
30-
pip3 install python-magic lxml junitparser gitlint pylint pykwalify
30+
pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint
3131
pip3 install west
3232
3333
- name: west setup

.yamllint

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
extends: default
4+
5+
rules:
6+
line-length:
7+
max: 100
8+
comments:
9+
min-spaces-from-content: 1
10+
indentation:
11+
spaces: 2
12+
indent-sequences: consistent
13+
document-start:
14+
present: false
15+
truthy:
16+
check-keys: false

scripts/ci/check_compliance.py

+32
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import traceback
1818
import shlex
1919

20+
from yamllint import config, linter
21+
2022
from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure
2123
import magic
2224

@@ -991,6 +993,36 @@ def run(self):
991993
self.failure(f"Error parsing {file}: {ex}")
992994

993995

996+
class YAMLLint(ComplianceTest):
997+
"""
998+
YAMLLint
999+
"""
1000+
name = "YAMLLint"
1001+
doc = "Check YAML files with YAMLLint."
1002+
path_hint = "<git-top>"
1003+
1004+
def run(self):
1005+
config_file = os.path.join(ZEPHYR_BASE, ".yamllint")
1006+
1007+
for file in get_files(filter="d"):
1008+
if Path(file).suffix not in ['.yaml', '.yml']:
1009+
continue
1010+
1011+
yaml_config = config.YamlLintConfig(file=config_file)
1012+
1013+
if file.startswith(".github/"):
1014+
# Tweak few rules for workflow files.
1015+
yaml_config.rules["line-length"] = False
1016+
yaml_config.rules["truthy"]["allowed-values"].extend(['on', 'off'])
1017+
elif file == ".codecov.yml":
1018+
yaml_config.rules["truthy"]["allowed-values"].extend(['yes', 'no'])
1019+
1020+
with open(file, 'r') as fp:
1021+
for p in linter.run(fp, yaml_config):
1022+
self.fmtd_failure('warning', f'YAMLLint ({p.rule})', file,
1023+
p.line, col=p.column, desc=p.desc)
1024+
1025+
9941026
def init_logs(cli_arg):
9951027
# Initializes logging
9961028

scripts/requirements-compliance.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ python-magic-bin; sys_platform == "win32"
66
lxml
77
junitparser>=2
88
pylint
9+
yamllint

0 commit comments

Comments
 (0)