mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 10:46:54 +00:00
Wire-up --statistics again
I'm not sure where this code went or when, but it disappeared. Let's add it back. Related #180
This commit is contained in:
parent
fc035c4df2
commit
4dc1d11a62
3 changed files with 31 additions and 0 deletions
|
|
@ -85,6 +85,19 @@ class BaseFormatter(object):
|
|||
raise NotImplementedError('Subclass of BaseFormatter did not implement'
|
||||
' format.')
|
||||
|
||||
def show_statistics(self, statistics):
|
||||
"""Format and print the statistics."""
|
||||
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)
|
||||
self._write('{count:<5} {error_code} {message}'.format(
|
||||
count=count,
|
||||
error_code=error_code,
|
||||
message=statistic.message,
|
||||
))
|
||||
|
||||
def show_benchmarks(self, benchmarks):
|
||||
"""Format and print the benchmarks."""
|
||||
# NOTE(sigmavirus24): The format strings are a little confusing, even
|
||||
|
|
|
|||
|
|
@ -263,6 +263,13 @@ class Application(object):
|
|||
LOG.info('Found a total of %d violations and reported %d',
|
||||
self.total_result_count, self.result_count)
|
||||
|
||||
def report_statistics(self):
|
||||
"""Aggregate and report statistics from this run."""
|
||||
if not self.options.statistics:
|
||||
return
|
||||
|
||||
self.formatter.show_statistics(self.guide.stats)
|
||||
|
||||
def initialize(self, argv):
|
||||
# type: () -> NoneType
|
||||
"""Initialize the application to be run.
|
||||
|
|
@ -285,6 +292,7 @@ class Application(object):
|
|||
self.initialize(argv)
|
||||
self.run_checks()
|
||||
self.report_errors()
|
||||
self.report_statistics()
|
||||
self.report_benchmarks()
|
||||
|
||||
def run(self, argv=None):
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@ class Statistics(object):
|
|||
"""Initialize the underlying dictionary for our statistics."""
|
||||
self._store = {}
|
||||
|
||||
def error_codes(self):
|
||||
"""Return all unique error codes stored.
|
||||
|
||||
:returns:
|
||||
Sorted list of error codes.
|
||||
:rtype:
|
||||
list(str)
|
||||
"""
|
||||
return list(sorted(set(key.code for key in self._store.keys())))
|
||||
|
||||
def record(self, error):
|
||||
"""Add the fact that the error was seen in the file.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue