def show_statistics(self, statistics: Statistics) -> None: # noqa: WPS210 """Called when ``--statistic`` option is passed.""" all_errors = 0 for error_code in statistics.error_codes(): stats_for_error_code = statistics.statistics_for(error_code) statistic = next(stats_for_error_code) count = statistic.count count += sum(stat.count for stat in stats_for_error_code) all_errors += count error_by_file = _count_per_filename(statistics, error_code) self._write( '{newline}{error_code}: {message}'.format( newline=self.newline, error_code=_bold(error_code), message=statistic.message, ), ) for filename in error_by_file: self._write( ' {error_count:<5} {filename}'.format( error_count=error_by_file[filename], filename=filename, ), ) self._write(_underline('Total: {0}'.format(count))) self._write(self.newline) self._write(_underline(_bold('All errors: {0}'.format(all_errors))))
def _count_per_filename( statistics: Statistics, error_code: str, ) -> DefaultDict[str, int]: filenames: DefaultDict[str, int] = defaultdict(int) stats_for_error_code = statistics.statistics_for(error_code) for stat in stats_for_error_code: filenames[stat.filename] += stat.count return filenames
def show_statistics(self, statistics: Statistics) -> None: # noqa: WPS210 """Called when ``--statistic`` option is passed.""" all_errors = 0 for error_code in statistics.error_codes(): stats_for_error_code = statistics.statistics_for(error_code) statistic = next(stats_for_error_code) count = statistic.count count += sum(stat.count for stat in stats_for_error_code) all_errors += count error_by_file = _count_per_filename(statistics, error_code) self._print_violation_per_file( statistic, error_code, count, error_by_file, ) self._write(self.newline) self._write(_underline(_bold('All errors: {0}'.format(all_errors))))