Skip to content

Commit

Permalink
scripts: compliance: add support for YAMLLint
Browse files Browse the repository at this point in the history
Add a YAMLLint compliance check that uses the yamllint package to report
linting error on YAML files.

Signed-off-by: Fabio Baltieri <[email protected]>
  • Loading branch information
fabiobaltieri authored and carlescufi committed Jan 4, 2023
1 parent 888607d commit 9d3681c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
pip3 install setuptools
pip3 install wheel
pip3 install python-magic lxml junitparser gitlint pylint pykwalify
pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint
pip3 install west
- name: west setup
Expand Down
16 changes: 16 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: Apache-2.0

extends: default

rules:
line-length:
max: 100
comments:
min-spaces-from-content: 1
indentation:
spaces: 2
indent-sequences: consistent
document-start:
present: false
truthy:
check-keys: false
32 changes: 32 additions & 0 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import traceback
import shlex

from yamllint import config, linter

from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure
import magic

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


class YAMLLint(ComplianceTest):
"""
YAMLLint
"""
name = "YAMLLint"
doc = "Check YAML files with YAMLLint."
path_hint = "<git-top>"

def run(self):
config_file = os.path.join(ZEPHYR_BASE, ".yamllint")

for file in get_files(filter="d"):
if Path(file).suffix not in ['.yaml', '.yml']:
continue

yaml_config = config.YamlLintConfig(file=config_file)

if file.startswith(".github/"):
# Tweak few rules for workflow files.
yaml_config.rules["line-length"] = False
yaml_config.rules["truthy"]["allowed-values"].extend(['on', 'off'])
elif file == ".codecov.yml":
yaml_config.rules["truthy"]["allowed-values"].extend(['yes', 'no'])

with open(file, 'r') as fp:
for p in linter.run(fp, yaml_config):
self.fmtd_failure('warning', f'YAMLLint ({p.rule})', file,
p.line, col=p.column, desc=p.desc)


def init_logs(cli_arg):
# Initializes logging

Expand Down
1 change: 1 addition & 0 deletions scripts/requirements-compliance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ python-magic-bin; sys_platform == "win32"
lxml
junitparser>=2
pylint
yamllint

0 comments on commit 9d3681c

Please sign in to comment.