Skip to content

Commit 61a461e

Browse files
[pylint.message] Add a location attribute to 'pylint.Message'
1 parent 113a152 commit 61a461e

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

pylint/message/message.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,16 @@ def format(self, template: str) -> str:
7777
cf. https://docs.python.org/2/library/string.html#formatstrings
7878
"""
7979
return template.format(**asdict(self))
80+
81+
@property
82+
def location(self) -> MessageLocationTuple:
83+
return MessageLocationTuple(
84+
self.abspath,
85+
self.path,
86+
self.module,
87+
self.obj,
88+
self.line,
89+
self.column,
90+
self.end_line,
91+
self.end_column,
92+
)

pylint/reporters/json_reporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def display_messages(self, layout: Section | None) -> None:
3232

3333
@staticmethod
3434
def serialize(message: Message) -> dict[str, int | str | None]:
35-
# TODO (3.0) add abs-path and confidence
35+
# TODO: 3.0: Add abs-path and confidence or a new JSONReporter
3636
return {
3737
"type": message.category,
3838
"module": message.module,
@@ -54,7 +54,7 @@ def deserialize(message_as_json: dict) -> Message:
5454
symbol=message_as_json["symbol"],
5555
msg=message_as_json["message"],
5656
location=MessageLocationTuple(
57-
# TODO (3.0) abs-path is not available in json export
57+
# TODO: 3.0: Add abs-path and confidence or a new JSONReporter
5858
abspath=message_as_json["path"],
5959
path=message_as_json["path"],
6060
module=message_as_json["module"],
@@ -64,7 +64,7 @@ def deserialize(message_as_json: dict) -> Message:
6464
end_line=message_as_json["endLine"],
6565
end_column=message_as_json["endColumn"],
6666
),
67-
# TODO (3.0) confidence is not available in json export
67+
# TODO: 3.0: Make confidence available or a new JSONReporter
6868
confidence=UNDEFINED,
6969
)
7070

tests/message/unittest_message.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@ def build_message(
5555
)
5656
e1234 = build_message(e1234_message_definition, e1234_location_values)
5757
w1234 = build_message(w1234_message_definition, w1234_location_values)
58+
assert e1234.location == e1234_location_values
59+
assert w1234.location == w1234_location_values
5860
assert e1234.format(template) == expected
5961
assert w1234.format(template) == "8:11:12: W1234: message (msg-symbol)"

tests/reporters/unittest_json_reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,6 @@ def get_linter_result(score: bool, message: dict[str, Any]) -> list[dict[str, An
132132
],
133133
)
134134
def test_serialize_deserialize(message):
135-
# TODO (3.0): Add confidence handling, add path and abs path handling
135+
# TODO: 3.0: Add confidence handling, add path and abs path handling or a new JSONReporter
136136
json_message = JSONReporter.serialize(message)
137137
assert message == JSONReporter.deserialize(json_message)

0 commit comments

Comments
 (0)