1010import sys
1111from typing import TYPE_CHECKING , Optional
1212
13- from pylint .interfaces import UNDEFINED
13+ from pylint .interfaces import UNDEFINED , Confidence
1414from pylint .message import Message
1515from pylint .reporters .base_reporter import BaseReporter
1616from pylint .typing import MessageLocationTuple
4343)
4444
4545
46+ class JSONExport (OldJsonExport ): # pylint: disable=inherit-non-class
47+ confidence : Confidence
48+ abspath : str
49+
50+
4651class BaseJSONReporter (BaseReporter ):
4752 """Report messages and layouts in JSON."""
4853
@@ -74,9 +79,6 @@ class JSONReporter(BaseJSONReporter):
7479 """
7580 TODO: 3.0: Remove this JSONReporter in favor of the new one handling abs-path
7681 and confidence.
77-
78- TODO: 2.15: Add a new JSONReporter handling abs-path, confidence and scores.
79- (Ultimately all other breaking change related to json for 3.0).
8082 """
8183
8284 @staticmethod
@@ -102,7 +104,6 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
102104 symbol = message_as_json ["symbol" ],
103105 msg = message_as_json ["message" ],
104106 location = MessageLocationTuple (
105- # TODO: 3.0: Add abs-path and confidence in a new JSONReporter
106107 abspath = message_as_json ["path" ],
107108 path = message_as_json ["path" ],
108109 module = message_as_json ["module" ],
@@ -112,10 +113,56 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
112113 end_line = message_as_json ["endLine" ],
113114 end_column = message_as_json ["endColumn" ],
114115 ),
115- # TODO: 3.0: Make confidence available in a new JSONReporter
116116 confidence = UNDEFINED ,
117117 )
118118
119119
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+
120166def register (linter : PyLinter ) -> None :
121167 linter .register_reporter (JSONReporter )
168+ linter .register_reporter (NewJSONReporter )
0 commit comments