summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-06-27 16:30:39 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-06-29 10:19:55 +0200
commit640f92449d0e76c1bbad4084867030c470dc4689 (patch)
tree94edf64d2c96478e4bbe4687712443c8b11aafd6
parent1b7965a028fecabfd1488f4c5c50b8172fcec217 (diff)
downloadpylint-git-640f92449d0e76c1bbad4084867030c470dc4689.tar.gz
[pylint.message] Add a location attribute to 'pylint.Message'
-rw-r--r--pylint/message/message.py13
-rw-r--r--pylint/reporters/json_reporter.py6
-rw-r--r--tests/message/unittest_message.py2
-rw-r--r--tests/reporters/unittest_json_reporter.py2
4 files changed, 19 insertions, 4 deletions
diff --git a/pylint/message/message.py b/pylint/message/message.py
index 4efa3f124..11961d9af 100644
--- a/pylint/message/message.py
+++ b/pylint/message/message.py
@@ -77,3 +77,16 @@ class Message: # pylint: disable=too-many-instance-attributes
cf. https://docs.python.org/2/library/string.html#formatstrings
"""
return template.format(**asdict(self))
+
+ @property
+ def location(self) -> MessageLocationTuple:
+ return MessageLocationTuple(
+ self.abspath,
+ self.path,
+ self.module,
+ self.obj,
+ self.line,
+ self.column,
+ self.end_line,
+ self.end_column,
+ )
diff --git a/pylint/reporters/json_reporter.py b/pylint/reporters/json_reporter.py
index 59b596f3f..1d6d6ab86 100644
--- a/pylint/reporters/json_reporter.py
+++ b/pylint/reporters/json_reporter.py
@@ -32,7 +32,7 @@ class JSONReporter(BaseReporter):
@staticmethod
def serialize(message: Message) -> dict[str, int | str | None]:
- # TODO (3.0) add abs-path and confidence
+ # TODO: 3.0: Add abs-path and confidence or a new JSONReporter
return {
"type": message.category,
"module": message.module,
@@ -54,7 +54,7 @@ class JSONReporter(BaseReporter):
symbol=message_as_json["symbol"],
msg=message_as_json["message"],
location=MessageLocationTuple(
- # TODO (3.0) abs-path is not available in json export
+ # TODO: 3.0: Add abs-path and confidence or a new JSONReporter
abspath=message_as_json["path"],
path=message_as_json["path"],
module=message_as_json["module"],
@@ -64,7 +64,7 @@ class JSONReporter(BaseReporter):
end_line=message_as_json["endLine"],
end_column=message_as_json["endColumn"],
),
- # TODO (3.0) confidence is not available in json export
+ # TODO: 3.0: Make confidence available or a new JSONReporter
confidence=UNDEFINED,
)
diff --git a/tests/message/unittest_message.py b/tests/message/unittest_message.py
index d0805e337..edb803daf 100644
--- a/tests/message/unittest_message.py
+++ b/tests/message/unittest_message.py
@@ -55,5 +55,7 @@ def test_new_message(message_definitions: ValuesView[MessageDefinition]) -> None
)
e1234 = build_message(e1234_message_definition, e1234_location_values)
w1234 = build_message(w1234_message_definition, w1234_location_values)
+ assert e1234.location == e1234_location_values
+ assert w1234.location == w1234_location_values
assert e1234.format(template) == expected
assert w1234.format(template) == "8:11:12: W1234: message (msg-symbol)"
diff --git a/tests/reporters/unittest_json_reporter.py b/tests/reporters/unittest_json_reporter.py
index fd29d8ea8..90a67fceb 100644
--- a/tests/reporters/unittest_json_reporter.py
+++ b/tests/reporters/unittest_json_reporter.py
@@ -132,6 +132,6 @@ def get_linter_result(score: bool, message: dict[str, Any]) -> list[dict[str, An
],
)
def test_serialize_deserialize(message):
- # TODO (3.0): Add confidence handling, add path and abs path handling
+ # TODO: 3.0: Add confidence handling, add path and abs path handling or a new JSONReporter
json_message = JSONReporter.serialize(message)
assert message == JSONReporter.deserialize(json_message)