Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document syntax-check as unskippable #1606

Merged
merged 1 commit into from Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
16 changes: 14 additions & 2 deletions src/ansiblelint/rules/AnsibleSyntaxCheckRule.py
Expand Up @@ -13,6 +13,18 @@
from ansiblelint.rules import AnsibleLintRule
from ansiblelint.text import strip_ansi_escape

DESCRIPTION = """\
Running ``ansible-playbook --syntax-check ...`` failed.

This error **cannot be disabled** due to being 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 fallback values.
"""

_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 +41,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