diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-25 19:57:36 +0000 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-25 19:57:36 +0000 |
| commit | 667a01f8df8a537216494e26e92b2a6e8633f24e (patch) | |
| tree | 7cf794a50c10eeda3f765111ceb6e6db481d460d /src | |
| parent | 427c4b53ef349cb31ff7beafdfe6ca9f955fe02d (diff) | |
| parent | 4dc1d11a627a571eeae4e0ae3da7b94e7de04214 (diff) | |
| download | flake8-667a01f8df8a537216494e26e92b2a6e8633f24e.tar.gz | |
Merge branch 'bug/180' into 'master'
Wire-up --statistics again
*Description of changes*
Make `--statistics` work again
*Related to:* #180
See merge request !87
Diffstat (limited to 'src')
| -rw-r--r-- | src/flake8/formatting/base.py | 13 | ||||
| -rw-r--r-- | src/flake8/main/application.py | 8 | ||||
| -rw-r--r-- | src/flake8/statistics.py | 10 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py index 7c2e4b5..c4a626b 100644 --- a/src/flake8/formatting/base.py +++ b/src/flake8/formatting/base.py @@ -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 diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 8269dc1..5a9866f 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -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. @@ -286,6 +293,7 @@ class Application(object): self.run_checks() self.formatter.start() self.report_errors() + self.report_statistics() self.report_benchmarks() self.formatter.stop() diff --git a/src/flake8/statistics.py b/src/flake8/statistics.py index 2512089..d35d4bf 100644 --- a/src/flake8/statistics.py +++ b/src/flake8/statistics.py @@ -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. |
