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 ):
47
+ confidence : Confidence
48
+ abspath : str
49
+
50
+
46
51
class BaseJSONReporter (BaseReporter ):
47
52
"""Report messages and layouts in JSON."""
48
53
@@ -69,15 +74,9 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
69
74
raise NotImplementedError
70
75
71
76
72
- class JSONReporter (BaseJSONReporter ):
77
+ class OldJSONReporter (BaseJSONReporter ):
73
78
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."""
81
80
82
81
@staticmethod
83
82
def serialize (message : Message ) -> OldJsonExport :
@@ -102,7 +101,6 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
102
101
symbol = message_as_json ["symbol" ],
103
102
msg = message_as_json ["message" ],
104
103
location = MessageLocationTuple (
105
- # TODO: 3.0: Add abs-path and confidence in a new JSONReporter
106
104
abspath = message_as_json ["path" ],
107
105
path = message_as_json ["path" ],
108
106
module = message_as_json ["module" ],
@@ -112,10 +110,49 @@ def deserialize(message_as_json: OldJsonExport) -> Message:
112
110
end_line = message_as_json ["endLine" ],
113
111
end_column = message_as_json ["endColumn" ],
114
112
),
115
- # TODO: 3.0: Make confidence available in a new JSONReporter
116
113
confidence = UNDEFINED ,
117
114
)
118
115
119
116
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
+
120
156
def register (linter : PyLinter ) -> None :
157
+ linter .register_reporter (OldJSONReporter )
121
158
linter .register_reporter (JSONReporter )
0 commit comments