10
10
import sys
11
11
from typing import TYPE_CHECKING , Optional
12
12
13
- from pylint .interfaces import UNDEFINED
13
+ from pylint .interfaces import UNDEFINED , Confidence
14
14
from pylint .message import Message
15
15
from pylint .reporters .base_reporter import BaseReporter
16
16
from pylint .typing import MessageLocationTuple
43
43
)
44
44
45
45
46
+ class JSONExport (OldJsonExport ): # pylint: disable=inherit-non-class
47
+ confidence : Confidence
48
+ abspath : str
49
+
50
+
46
51
class BaseJSONReporter (BaseReporter ):
47
52
"""Report messages and layouts in JSON."""
48
53
@@ -74,9 +79,6 @@ class JSONReporter(BaseJSONReporter):
74
79
"""
75
80
TODO: 3.0: Remove this JSONReporter in favor of the new one handling abs-path
76
81
and confidence.
77
-
78
- TODO: 2.16: Add a new JSONReporter handling abs-path, confidence and scores.
79
- (Ultimately all other breaking change related to json for 3.0).
80
82
"""
81
83
82
84
@staticmethod
@@ -102,7 +104,6 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
102
104
symbol = message_as_json ["symbol" ],
103
105
msg = message_as_json ["message" ],
104
106
location = MessageLocationTuple (
105
- # TODO: 3.0: Add abs-path and confidence in a new JSONReporter
106
107
abspath = message_as_json ["path" ],
107
108
path = message_as_json ["path" ],
108
109
module = message_as_json ["module" ],
@@ -112,10 +113,56 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
112
113
end_line = message_as_json ["endLine" ],
113
114
end_column = message_as_json ["endColumn" ],
114
115
),
115
- # TODO: 3.0: Make confidence available in a new JSONReporter
116
116
confidence = UNDEFINED ,
117
117
)
118
118
119
119
120
+ class NewJSONReporter (BaseJSONReporter ):
121
+
122
+ """
123
+ TODO: 3.0: Refactor this reporter so it's the only reporter.
124
+
125
+ TODO: 3.0: Handle all other breaking changes related to json for 3.0
126
+ """
127
+
128
+ @staticmethod
129
+ def serialize (message : Message ) -> JSONExport :
130
+ return {
131
+ "type" : message .category ,
132
+ "module" : message .module ,
133
+ "obj" : message .obj ,
134
+ "line" : message .line ,
135
+ "column" : message .column ,
136
+ "endLine" : message .end_line ,
137
+ "endColumn" : message .end_column ,
138
+ "path" : message .path ,
139
+ "symbol" : message .symbol ,
140
+ "message" : message .msg or "" ,
141
+ "message-id" : message .msg_id ,
142
+ "confidence" : message .confidence ,
143
+ "abspath" : message .abspath ,
144
+ }
145
+
146
+ @staticmethod
147
+ def deserialize (message_as_json : JSONExport ) -> Message :
148
+ return Message (
149
+ msg_id = message_as_json ["message-id" ],
150
+ symbol = message_as_json ["symbol" ],
151
+ msg = message_as_json ["message" ],
152
+ location = MessageLocationTuple (
153
+ abspath = message_as_json ["abspath" ],
154
+ path = message_as_json ["path" ],
155
+ module = message_as_json ["module" ],
156
+ obj = message_as_json ["obj" ],
157
+ line = message_as_json ["line" ],
158
+ column = message_as_json ["column" ],
159
+ end_line = message_as_json ["endLine" ],
160
+ end_column = message_as_json ["endColumn" ],
161
+ ),
162
+ confidence = message_as_json ["confidence" ],
163
+ )
164
+
165
+
120
166
def register (linter : PyLinter ) -> None :
121
167
linter .register_reporter (JSONReporter )
168
+ linter .register_reporter (NewJSONReporter )
0 commit comments