From ad8011186772fa627579ba39cd6bbd92075ee98e Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 4 Jun 2021 10:09:53 +0100 Subject: [PATCH] Document syntax-check as unskippable Fixes: #1594 --- src/ansiblelint/__main__.py | 27 ++++++++++++------- .../rules/AnsibleSyntaxCheckRule.py | 16 +++++++++-- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 0cfdfd1a7d..17fe82f11d 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -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. @@ -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 @@ -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): @@ -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 @@ -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) " diff --git a/src/ansiblelint/rules/AnsibleSyntaxCheckRule.py b/src/ansiblelint/rules/AnsibleSyntaxCheckRule.py index 267c2b3b02..25f57eb165 100644 --- a/src/ansiblelint/rules/AnsibleSyntaxCheckRule.py +++ b/src/ansiblelint/rules/AnsibleSyntaxCheckRule.py @@ -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[^\n]*)\n\nThe error appears to be in " r"'(?P<filename>.*)': line (?P<line>\d+), column (?P<column>\d+)", @@ -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