Skip to content

Commit

Permalink
Allow user to make yamllint rule mandatory
Browse files Browse the repository at this point in the history
Related: #1538
  • Loading branch information
ssbarnea committed May 3, 2021
1 parent d1dbd87 commit 2f7f255
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .ansible-lint
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.in
Expand Up @@ -4,3 +4,4 @@ pipdeptree
Sphinx
sphinx_ansible_theme
sphinxcontrib-programoutput2>=2.0a1
yamllint
14 changes: 8 additions & 6 deletions docs/requirements.txt
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/ansiblelint/rules/YamllintRule.py
Expand Up @@ -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
Expand All @@ -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 = """
Expand All @@ -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.
"""


Expand Down
4 changes: 2 additions & 2 deletions test-requirements.txt
Expand Up @@ -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:
Expand Down

0 comments on commit 2f7f255

Please sign in to comment.