def _render_matches( matches: List, options: "Namespace", formatter: Any, cwd: Union[str, pathlib.Path]): ignored_matches = [match for match in matches if match.ignored] fatal_matches = [match for match in matches if not match.ignored] # Displayed ignored matches first if ignored_matches: _logger.warning( "Listing %s violation(s) marked as ignored, likely already known", len(ignored_matches)) for match in ignored_matches: if match.ignored: # highlight must be off or apostrophes may produce unexpected results console.print( formatter.format(match), highlight=False) if fatal_matches: _logger.warning("Listing %s violation(s) that are fatal", len(fatal_matches)) for match in fatal_matches: if not match.ignored: console.print(formatter.format(match), highlight=False) # If run under GitHub Actions we also want to emit output recognized by it. if os.getenv('GITHUB_ACTIONS') == 'true' and os.getenv('GITHUB_WORKFLOW'): formatter = formatters.AnnotationsFormatter(cwd, True) for match in matches: console.print(formatter.format(match), markup=False, highlight=False)
def render_matches(self, matches: List) -> None: """Display given matches.""" if isinstance(self.formatter, formatters.CodeclimateJSONFormatter): # If formatter CodeclimateJSONFormatter is chosen, # then print only the matches in JSON console.print( self.formatter.format_result(matches), markup=False, highlight=False ) return None ignored_matches = [match for match in matches if match.ignored] fatal_matches = [match for match in matches if not match.ignored] # Displayed ignored matches first if ignored_matches: _logger.warning( "Listing %s violation(s) marked as ignored, likely already known", len(ignored_matches), ) for match in ignored_matches: if match.ignored: # highlight must be off or apostrophes may produce unexpected results console.print(self.formatter.format(match), highlight=False) if fatal_matches: _logger.warning( "Listing %s violation(s) that are fatal", len(fatal_matches) ) for match in fatal_matches: if not match.ignored: console.print(self.formatter.format(match), highlight=False) # If run under GitHub Actions we also want to emit output recognized by it. if os.getenv('GITHUB_ACTIONS') == 'true' and os.getenv('GITHUB_WORKFLOW'): formatter = formatters.AnnotationsFormatter(self.options.cwd, True) for match in matches: console.print(formatter.format(match), markup=False, highlight=False)
def _render_matches(matches: List, options: "Namespace", formatter: Any, cwd: Union[str, pathlib.Path]): ignored_matches = [match for match in matches if match.ignored] fatal_matches = [match for match in matches if not match.ignored] # Displayed ignored matches first if ignored_matches: _logger.warning( "Listing %s violation(s) marked as ignored, likely already known", len(ignored_matches)) for match in ignored_matches: if match.ignored: print(formatter.format(match, options.colored)) if fatal_matches: _logger.warning("Listing %s violation(s) that are fatal", len(fatal_matches)) for match in fatal_matches: if not match.ignored: print(formatter.format(match, options.colored)) # If run under GitHub Actions we also want to emit output recognized by it. if os.getenv('GITHUB_ACTIONS') == 'true' and os.getenv('GITHUB_WORKFLOW'): formatter = formatters.AnnotationsFormatter(cwd, True) for match in matches: print(formatter.format(match))
def main() -> int: """Linter CLI entry point.""" cwd = pathlib.Path.cwd() options = cli.get_config(sys.argv[1:]) initialize_logger(options.verbosity) _logger.debug("Options: %s", options) formatter_factory = choose_formatter_factory(options) formatter = formatter_factory(cwd, options.display_relative_path) rulesdirs = get_rules_dirs([str(rdir) for rdir in options.rulesdir], options.use_default_rules) rules = RulesCollection(rulesdirs) if options.listrules: console.print(_rule_format_map[options.format](rules), highlight=False) return 0 if options.listtags: print(rules.listtags()) return 0 if isinstance(options.tags, str): options.tags = options.tags.split(',') skip = set() for s in options.skip_list: skip.update(str(s).split(',')) options.skip_list = frozenset(skip) if not options.playbook: # no args triggers auto-detection mode playbooks = get_playbooks_and_roles(options=options) else: playbooks = sorted(set(options.playbook)) matches = list() checked_files: Set[str] = set() for playbook in playbooks: runner = Runner(rules, playbook, options.tags, options.skip_list, options.exclude_paths, options.verbosity, checked_files) matches.extend(runner.run()) # Assure we do not print duplicates and the order is consistent matches = sorted(set(matches)) for match in matches: print(formatter.format(match, options.colored)) # If run under GitHub Actions we also want to emit output recognized by it. if os.getenv('GITHUB_ACTIONS') == 'true' and os.getenv('GITHUB_WORKFLOW'): formatter = formatters.AnnotationsFormatter(cwd, True) for match in matches: print(formatter.format(match)) if matches: return report_outcome(matches, options=options) else: return 0
def main() -> int: """Linter CLI entry point.""" cwd = pathlib.Path.cwd() options = cli.get_config(sys.argv[1:]) initialize_logger(options.verbosity) _logger.debug("Options: %s", options) formatter_factory: Any = formatters.Formatter if options.quiet: formatter_factory = formatters.QuietFormatter if options.parseable: formatter_factory = formatters.ParseableFormatter if options.parseable_severity: formatter_factory = formatters.ParseableSeverityFormatter formatter = formatter_factory(cwd, options.display_relative_path) if options.use_default_rules: rulesdirs = options.rulesdir + [DEFAULT_RULESDIR] else: rulesdirs = options.rulesdir or [DEFAULT_RULESDIR] rules = RulesCollection(rulesdirs) if options.listrules: formatted_rules = rules if options.format == 'plain' else rules_as_rst( rules) print(formatted_rules) return 0 if options.listtags: print(rules.listtags()) return 0 if isinstance(options.tags, str): options.tags = options.tags.split(',') skip = set() for s in options.skip_list: skip.update(str(s).split(',')) options.skip_list = frozenset(skip) if not options.playbook: # no args triggers auto-detection mode playbooks = get_playbooks_and_roles(options=options) else: playbooks = sorted(set(options.playbook)) matches = list() checked_files: Set[str] = set() for playbook in playbooks: runner = Runner(rules, playbook, options.tags, options.skip_list, options.exclude_paths, options.verbosity, checked_files) matches.extend(runner.run()) # Assure we do not print duplicates and the order is consistent matches = sorted(set(matches)) for match in matches: print(formatter.format(match, options.colored)) # If run under GitHub Actions we also want to emit output recognized by it. if os.getenv('GITHUB_ACTIONS') == 'true' and os.getenv('GITHUB_WORKFLOW'): formatter = formatters.AnnotationsFormatter(cwd, True) for match in matches: print(formatter.format(match)) if matches: return 2 else: return 0