3232#
3333
3434# stdlib
35+ import json
3536from functools import partial
3637from gettext import ngettext
3738from io import StringIO
38- from typing import Optional , Tuple , Type
39+ from typing import List , Optional , Tuple , Type
3940
4041# 3rd party
4142import click
4243import flake8 .main .application # type: ignore
4344from flake8 .formatting .base import BaseFormatter # type: ignore
4445from flake8_json_reporter .reporters import DefaultJSON # type: ignore
46+ from typing_extensions import NoReturn
47+
48+ # this package
49+ from flake8_github_action .annotation import Annotation
4550
4651__all__ = ["Application" , "JsonFormatter" ]
4752
@@ -54,31 +59,31 @@ class Application(flake8.main.application.Application):
5459 Subclass of Flake8's ``Application``.
5560 """
5661
57- def exit (self ) -> None :
62+ def exit (self ) -> NoReturn :
5863 """
5964 Handle finalization and exiting the program.
6065
6166 This should be the last thing called on the application instance.
6267 It will check certain options and exit appropriately.
6368 """
6469
65- # if self.options.count:
66- if True :
67- files_checked = self .file_checker_manager .statistics ["files" ]
68- files_with_errors = self .file_checker_manager .statistics ["files_with_errors" ]
69- if self .result_count :
70- click .echo (
71- f"Found { self .result_count } { _error (self .result_count )} "
72- f"in { files_with_errors } { _file (files_with_errors )} "
73- f"(checked { files_checked } source { _file (files_checked )} )"
74- )
75- else :
76- click .echo (f"Success: no issues found in { files_checked } source { _file (files_checked )} " )
77-
78- # if self.options.exit_zero:
79- # raise SystemExit(self.catastrophic_failure)
80- # else:
81- # raise SystemExit((self.result_count > 0) or self.catastrophic_failure)
70+ if self .options .count :
71+ if True :
72+ files_checked = self .file_checker_manager .statistics ["files" ]
73+ files_with_errors = self .file_checker_manager .statistics ["files_with_errors" ]
74+ if self .result_count :
75+ click .echo (
76+ f"Found { self .result_count } { _error (self .result_count )} "
77+ f"in { files_with_errors } { _file (files_with_errors )} "
78+ f"(checked { files_checked } source { _file (files_checked )} )"
79+ )
80+ else :
81+ click .echo (f"Success: no issues found in { files_checked } source { _file (files_checked )} " )
82+
83+ if self .options .exit_zero :
84+ raise SystemExit (self .catastrophic_failure )
85+ else :
86+ raise SystemExit ((self .result_count > 0 ) or self .catastrophic_failure )
8287
8388 def report_errors (self ) -> None :
8489 """
@@ -122,10 +127,29 @@ def make_formatter(self, formatter_class: Optional[Type[BaseFormatter]] = None)
122127
123128 self .formatter = JsonFormatter (self .options )
124129
130+ def report (self ):
131+ """
132+ Report errors, statistics, and benchmarks.
133+ """
134+
135+ super ().report ()
136+
137+ annotations : List [Annotation ] = []
138+
139+ json_annotations = json .loads (self .formatter .output_fd .getvalue ()).items ()
140+ for filename , raw_annotations in json_annotations :
141+ annotations .extend (Annotation .from_flake8json (filename , ann ) for ann in raw_annotations )
142+
143+ for annotation in annotations :
144+ print (annotation .to_str ())
145+
125146
126147class JsonFormatter (DefaultJSON ):
127148
128149 def __init__ (self , * args , ** kwargs ):
129150 super ().__init__ (* args , ** kwargs )
130151
131152 self .output_fd = StringIO ()
153+
154+
155+
0 commit comments