def report_outcome(matches: List["MatchError"], options) -> int: """Display information about how to skip found rules. Returns exit code, 2 if errors were found, 0 when only warnings were found. """ failure = False msg = """\ You can skip specific rules or tags by adding them to your configuration file: ```yaml # .ansible-lint warn_list: # or 'skip_list' to silence them completely """ matches_unignored = [match for match in matches if not match.ignored] matched_rules = {match.rule.id: match.rule for match in matches_unignored} for id in sorted(matched_rules.keys()): if {id, *matched_rules[id].tags}.isdisjoint(options.warn_list): msg += f" - '{id}' # {matched_rules[id].shortdesc}\n" failure = True for match in matches: if "experimental" in match.rule.tags: msg += " - experimental # all rules tagged as experimental\n" break msg += "```" if matches and not options.quiet: console_stderr.print(Markdown(msg)) if failure: return 2 else: return 0
def report_outcome(result: "LintResult", options, mark_as_success=False) -> int: """Display information about how to skip found rules. Returns exit code, 2 if errors were found, 0 when only warnings were found. """ failures = 0 warnings = 0 msg = """\ # .ansible-lint warn_list: # or 'skip_list' to silence them completely """ matches_unignored = [ match for match in result.matches if not match.ignored ] # counting matched_rules = {match.rule.id: match.rule for match in matches_unignored} for match in result.matches: if {match.rule.id, *match.rule.tags}.isdisjoint(options.warn_list): failures += 1 else: warnings += 1 entries = [] for key in sorted(matched_rules.keys()): if {key, *matched_rules[key].tags}.isdisjoint(options.warn_list): entries.append(f" - {key} # {matched_rules[key].shortdesc}\n") for match in result.matches: if "experimental" in match.rule.tags: entries.append( " - experimental # all rules tagged as experimental\n") break msg += "".join(sorted(entries)) for k, v in used_old_tags.items(): _logger.warning( "Replaced deprecated tag '%s' with '%s' but it will become an " "error in the future.", k, v, ) 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) " f"on {len(result.files)} files.") if mark_as_success or not failures: return 0 return 2
def report_outcome(result: "LintResult", options, mark_as_success=False) -> int: """Display information about how to skip found rules. Returns exit code, 2 if errors were found, 0 when only warnings were found. """ failures = 0 warnings = 0 msg = """\ # .ansible-lint warn_list: # or 'skip_list' to silence them completely """ matches_unignored = [ match for match in result.matches if not match.ignored ] # counting matched_rules = {match.rule.id: match.rule for match in matches_unignored} for match in result.matches: if {match.rule.id, *match.rule.tags}.isdisjoint(options.warn_list): failures += 1 else: warnings += 1 for key in sorted(matched_rules.keys()): if {key, *matched_rules[key].tags}.isdisjoint(options.warn_list): msg += f" - '{key}' # {matched_rules[key].shortdesc}\n" for match in result.matches: if "experimental" in match.rule.tags: msg += " - experimental # all rules tagged as experimental\n" break 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) " f"on {len(result.files)} files.") if mark_as_success or not failures: return 0 return 2
def report_outcome( # noqa: C901 result: "LintResult", options: Namespace, mark_as_success: bool = False) -> int: """Display information about how to skip found rules. Returns exit code, 2 if errors were found, 0 when only warnings were found. """ failures = 0 warnings = 0 msg = "" matches_unignored = [ match for match in result.matches if not match.ignored ] # counting matched_rules = {match.rule.id: match.rule for match in matches_unignored} for match in result.matches: if {match.rule.id, *match.rule.tags}.isdisjoint(options.warn_list): failures += 1 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): entries.append(f" - {key} # {matched_rules[key].shortdesc}\n") for match in result.matches: if "experimental" in match.rule.tags: entries.append( " - experimental # all rules tagged as experimental\n") break if entries and not options.quiet: 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 # use ansible-lint 4 (for example, Ansible Galaxy and Automation Hub imports). If we # replace the old tags, those tools will report warnings. If we do not replace them, # ansible-lint 5 will report warnings. # # We can do the deprecation once the ecosystem caught up at least a bit. # for k, v in used_old_tags.items(): # _logger.warning( # "Replaced deprecated tag '%s' with '%s' but it will become an " # "error in the future.", # k, # v, # ) if result.matches and not options.quiet: console_stderr.print(render_yaml(msg)) console_stderr.print( f"Finished with {failures} failure(s), {warnings} warning(s) " f"on {len(result.files)} files.") if mark_as_success or not failures: return 0 return 2