diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index 3fb45e4a01..ebf20a0c20 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -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 diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000000..73bafc2cb1 --- /dev/null +++ b/.yamllint @@ -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 diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 7a8f13972d..c5fe9bc156 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -17,6 +17,8 @@ import tempfile import traceback import shlex +from yamllint import config, linter + from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure import magic @@ -991,6 +993,36 @@ class MaintainersFormat(ComplianceTest): self.failure(f"Error parsing {file}: {ex}") +class YAMLLint(ComplianceTest): + """ + YAMLLint + """ + name = "YAMLLint" + doc = "Check YAML files with YAMLLint." + path_hint = "" + + 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 diff --git a/scripts/requirements-compliance.txt b/scripts/requirements-compliance.txt index 240e953599..31c395ac4f 100644 --- a/scripts/requirements-compliance.txt +++ b/scripts/requirements-compliance.txt @@ -6,3 +6,4 @@ python-magic-bin; sys_platform == "win32" lxml junitparser>=2 pylint +yamllint