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 00ee9fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 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
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

0 comments on commit 00ee9fe

Please sign in to comment.