Skip to content

Commit

Permalink
Document syntax-check as unskippable
Browse files Browse the repository at this point in the history
Fixes: #1594
  • Loading branch information
ssbarnea committed Jun 4, 2021
1 parent e892ce9 commit 3401e6f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/ansiblelint/__main__.py
Expand Up @@ -118,7 +118,7 @@ def initialize_options(arguments: Optional[List[str]] = None) -> None:
)


def report_outcome(
def report_outcome( # noqa: C901
result: "LintResult", options: Namespace, mark_as_success: bool = False
) -> int:
"""Display information about how to skip found rules.
Expand All @@ -127,10 +127,7 @@ def report_outcome(
"""
failures = 0
warnings = 0
msg = """\
# .ansible-lint
warn_list: # or 'skip_list' to silence them completely
"""
msg = ""
matches_unignored = [match for match in result.matches if not match.ignored]

# counting
Expand All @@ -141,6 +138,11 @@ def report_outcome(
else:
warnings += 1

# remove unskippable rules from the list
for rule_id in list(matched_rules.keys()):
if 'unskippable' in matched_rules[rule_id].tags:
matched_rules.pop(rule_id)

entries = []
for key in sorted(matched_rules.keys()):
if {key, *matched_rules[key].tags}.isdisjoint(options.warn_list):
Expand All @@ -149,7 +151,16 @@ def report_outcome(
if "experimental" in match.rule.tags:
entries.append(" - experimental # all rules tagged as experimental\n")
break
msg += "".join(sorted(entries))
if entries:
console_stderr.print(
"You can skip specific rules or tags by adding them to your "
"configuration file:"
)
msg += """\
# .ansible-lint
warn_list: # or 'skip_list' to silence them completely
"""
msg += "".join(sorted(entries))

# Do not deprecate the old tags just yet. Why? Because it is not currently feasible
# to migrate old tags to new tags. There are a lot of things out there that still
Expand All @@ -167,10 +178,6 @@ def report_outcome(
# )

if result.matches and not options.quiet:
console_stderr.print(
"You can skip specific rules or tags by adding them to your "
"configuration file:"
)
console_stderr.print(render_yaml(msg))
console_stderr.print(
f"Finished with {failures} failure(s), {warnings} warning(s) "
Expand Down
17 changes: 15 additions & 2 deletions src/ansiblelint/rules/AnsibleSyntaxCheckRule.py
Expand Up @@ -13,6 +13,19 @@
from ansiblelint.rules import AnsibleLintRule
from ansiblelint.text import strip_ansi_escape

DESCRIPTION = """
Running ansible-playbook --syntax-check ... reported an error.
This error is caused by `ansible-playbook --syntax-check` failing to run and
cannot be disabled as passing it is a prerequisite for other steps. You can
either exclude these files from linting or better assure they can be loaded
by Ansible. This is often achieved by editing inventory file and/or
`ansible.cfg` so ansible can load required variables.
If undefined variables are the failure reason you could use jinja default()
filter in order to provide fallbacks.
"""

_ansible_syntax_check_re = re.compile(
r"^ERROR! (?P<title>[^\n]*)\n\nThe error appears to be in "
r"'(?P<filename>.*)': line (?P<line>\d+), column (?P<column>\d+)",
Expand All @@ -29,9 +42,9 @@ class AnsibleSyntaxCheckRule(AnsibleLintRule):

id = "syntax-check"
shortdesc = "Ansible syntax check failed"
description = "Running ansible-playbook --syntax-check ... reported an error."
description = DESCRIPTION
severity = "VERY_HIGH"
tags = ["core"]
tags = ["core", "unskippable"]
version_added = "v5.0.0"

@staticmethod
Expand Down

0 comments on commit 3401e6f

Please sign in to comment.