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 ):
47+ confidence : Confidence
48+ abspath : str
49+
50+
4651class BaseJSONReporter (BaseReporter ):
4752 """Report messages and layouts in JSON."""
4853
@@ -69,15 +74,9 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
6974 raise NotImplementedError
7075
7176
72- class JSONReporter (BaseJSONReporter ):
77+ class OldJSONReporter (BaseJSONReporter ):
7378
74- """
75- TODO: 3.0: Remove this JSONReporter in favor of the new one handling abs-path
76- and confidence.
77-
78- TODO: 3.0: Add a new JSONReporter handling abs-path, confidence and scores.
79- (Ultimately all other breaking change related to json for 3.0).
80- """
79+ """TODO: Remove in 4.0."""
8180
8281 @staticmethod
8382 def serialize (message : Message ) -> OldJsonExport :
@@ -102,7 +101,6 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
102101 symbol = message_as_json ["symbol" ],
103102 msg = message_as_json ["message" ],
104103 location = MessageLocationTuple (
105- # TODO: 3.0: Add abs-path and confidence in a new JSONReporter
106104 abspath = message_as_json ["path" ],
107105 path = message_as_json ["path" ],
108106 module = message_as_json ["module" ],
@@ -112,10 +110,49 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
112110 end_line = message_as_json ["endLine" ],
113111 end_column = message_as_json ["endColumn" ],
114112 ),
115- # TODO: 3.0: Make confidence available in a new JSONReporter
116113 confidence = UNDEFINED ,
117114 )
118115
119116
117+ class JSONReporter (BaseJSONReporter ):
118+ @staticmethod
119+ def serialize (message : Message ) -> JSONExport :
120+ return {
121+ "type" : message .category ,
122+ "module" : message .module ,
123+ "obj" : message .obj ,
124+ "line" : message .line ,
125+ "column" : message .column ,
126+ "endLine" : message .end_line ,
127+ "endColumn" : message .end_column ,
128+ "path" : message .path ,
129+ "symbol" : message .symbol ,
130+ "message" : message .msg or "" ,
131+ "message-id" : message .msg_id ,
132+ "confidence" : message .confidence ,
133+ "abspath" : message .abspath ,
134+ }
135+
136+ @staticmethod
137+ def deserialize (message_as_json : JSONExport ) -> Message :
138+ return Message (
139+ msg_id = message_as_json ["message-id" ],
140+ symbol = message_as_json ["symbol" ],
141+ msg = message_as_json ["message" ],
142+ location = MessageLocationTuple (
143+ abspath = message_as_json ["abspath" ],
144+ path = message_as_json ["path" ],
145+ module = message_as_json ["module" ],
146+ obj = message_as_json ["obj" ],
147+ line = message_as_json ["line" ],
148+ column = message_as_json ["column" ],
149+ end_line = message_as_json ["endLine" ],
150+ end_column = message_as_json ["endColumn" ],
151+ ),
152+ confidence = message_as_json ["confidence" ],
153+ )
154+
155+
120156def register (linter : PyLinter ) -> None :
157+ linter .register_reporter (OldJSONReporter )
121158 linter .register_reporter (JSONReporter )
0 commit comments