From 2f7f2553564a53aee75b159fb652dcafcecf5fa7 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 3 May 2021 12:31:27 +0100 Subject: [PATCH] Allow user to make yamllint rule mandatory Related: #1538 --- .ansible-lint | 4 +++- docs/requirements.in | 1 + docs/requirements.txt | 14 ++++++++------ src/ansiblelint/rules/YamllintRule.py | 11 ++++++++++- test-requirements.txt | 4 ++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.ansible-lint b/.ansible-lint index 23714aeecf..d8569fbed9 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -34,7 +34,9 @@ skip_list: # mentioned in the enable_list: enable_list: - no-same-owner - + # add yaml here if you want to avoid ignoring yaml checks when yamllint + # library is missing. Normally its absence just skips using that rule. + - yaml # Report only a subset of tags and fully ignore any others # tags: # - var-spacing diff --git a/docs/requirements.in b/docs/requirements.in index 4ba7e12ede..da94dab9e3 100644 --- a/docs/requirements.in +++ b/docs/requirements.in @@ -4,3 +4,4 @@ pipdeptree Sphinx sphinx_ansible_theme sphinxcontrib-programoutput2>=2.0a1 +yamllint diff --git a/docs/requirements.txt b/docs/requirements.txt index 9e757ed116..019623028b 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -5,9 +5,9 @@ # pip-compile --no-annotate --output-file=docs/requirements.txt docs/requirements.in setup.py # alabaster==0.7.12 -ansible-base==2.10.7 +ansible-base==2.10.8 attrs==20.3.0 -babel==2.9.0 +babel==2.9.1 bracex==2.1.1 certifi==2020.12.5 cffi==1.14.5 @@ -23,8 +23,9 @@ jinja2==2.11.3 markdown-it-py==0.6.2 markupsafe==1.1.1 mdit-py-plugins==0.2.6 -myst-parser==0.13.5 +myst-parser==0.13.7 packaging==20.9 +pathspec==0.8.1 pipdeptree==2.0.0 pycparser==2.20 pygments==2.8.1 @@ -34,13 +35,13 @@ pyyaml==5.4.1 requests==2.25.1 rich==10.1.0 ruamel.yaml.clib==0.2.2 -ruamel.yaml==0.17.2 ; python_version >= "3.7" +ruamel.yaml==0.17.4 ; python_version >= "3.7" six==1.15.0 snowballstemmer==2.1.0 sphinx-ansible-theme==0.3.2 sphinx-notfound-page==0.6 sphinx-rtd-theme==0.5.2 -sphinx==3.5.3 +sphinx==3.5.4 sphinxcontrib-applehelp==1.0.2 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==1.0.3 @@ -49,9 +50,10 @@ sphinxcontrib-programoutput2==2.0a1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.4 tenacity==7.0.0 -typing-extensions==3.7.4.3 +typing-extensions==3.10.0.0 urllib3==1.26.4 wcmatch==8.1.2 +yamllint==1.26.1 # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/src/ansiblelint/rules/YamllintRule.py b/src/ansiblelint/rules/YamllintRule.py index 1febc19aa3..33878aeaa0 100644 --- a/src/ansiblelint/rules/YamllintRule.py +++ b/src/ansiblelint/rules/YamllintRule.py @@ -3,6 +3,7 @@ import sys from typing import TYPE_CHECKING, List +from ansiblelint.config import options from ansiblelint.file_utils import Lintable from ansiblelint.rules import AnsibleLintRule from ansiblelint.skip_utils import get_rule_skips_from_line @@ -17,7 +18,11 @@ from yamllint.config import YamlLintConfig from yamllint.linter import run as run_yamllint except ImportError: - pass + # missing library is ignored unless yaml is exclitely added to enable_list + if 'yaml' in options.enable_list: + raise RuntimeError( + 'Failed to load yamllint library and ansible-linted was configured to require it.' + ) YAMLLINT_CONFIG = """ @@ -38,6 +43,10 @@ Specific tag identifiers that are printed at the end of rule name, like 'trailing-spaces' or 'indentation' can also be be skipped, allowing you to have a more fine control. + +By default this rule is not used hwne yamllint library is missing. If you want +to make its absence a runtime failure, please add 'yaml' to 'enable_list' +inside the configuration file. """ diff --git a/test-requirements.txt b/test-requirements.txt index 77ab55e052..dfe05d679b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -26,11 +26,11 @@ pytest==6.2.3 pyyaml==5.4.1 rich==10.1.0 ruamel.yaml.clib==0.2.2 -ruamel.yaml==0.17.2 ; python_version >= "3.7" +ruamel.yaml==0.17.4 ; python_version >= "3.7" six==1.15.0 tenacity==7.0.0 toml==0.10.2 -typing-extensions==3.7.4.3 +typing-extensions==3.10.0.0 wcmatch==8.1.2 # The following packages are considered to be unsafe in a requirements file: