Skip to content

Commit

Permalink
Revert changes to JSONReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Nov 24, 2021
1 parent 3c3f141 commit 6e91225
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 73 deletions.
2 changes: 0 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ Release date: TBA
end of a node to the output of Pylint. If these numbers are unknown, they are represented
by an empty string.

* Add ``end_line`` and ``end_column`` fields to the output of the ``JSONReporter``.

* Fix ``install graphiz`` message which isn't needed for puml output format.

* Fix ``simplify-boolean-expression`` when condition can be inferred as False.
Expand Down
2 changes: 0 additions & 2 deletions doc/whatsnew/2.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,3 @@ Other Changes
With the standard ``TextReporter`` this will add the line and column number of the
end of a node to the output of Pylint. If these numbers are unknown, they are represented
by an empty string.

* Add ``end_line`` and ``end_column`` fields to the output of the ``JSONReporter``.
2 changes: 0 additions & 2 deletions pylint/reporters/json_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def display_messages(self, layout: Optional["Section"]) -> None:
"obj": msg.obj,
"line": msg.line,
"column": msg.column,
"end_line": msg.end_line,
"end_column": msg.end_column,
"path": msg.path,
"symbol": msg.symbol,
"message": msg.msg or "",
Expand Down
80 changes: 17 additions & 63 deletions tests/unittest_reporters_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,29 @@
from pylint.reporters.ureports.nodes import EvaluationSection

expected_score_message = "Expected score message"


def test_simple_json_output_no_score() -> None:
"""Test JSON reporter with no score"""
message = {
"msg": "line-too-long",
"line": 1,
"args": (1, 2),
"end_line": None,
"end_column": None,
}
expected = [
[
("column", 0),
("end_column", None),
("end_line", None),
("line", 1),
("message", "Line too long (1/2)"),
("message-id", "C0301"),
("module", "0123"),
("obj", ""),
("path", "0123"),
("symbol", "line-too-long"),
("type", "convention"),
]
expected_result = [
[
("column", 0),
("line", 1),
("message", "Line too long (1/2)"),
("message-id", "C0301"),
("module", "0123"),
("obj", ""),
("path", "0123"),
("symbol", "line-too-long"),
("type", "convention"),
]
report = get_linter_result(score=False, message=message)
assert len(report) == 1
report_result = [sorted(report[0].items(), key=lambda item: item[0])]
assert report_result == expected
]


def test_simple_json_output_no_score_with_end_line() -> None:
"""Test JSON reporter with no score with end_line and end_column"""
message = {
"msg": "line-too-long",
"line": 1,
"args": (1, 2),
"end_line": 1,
"end_column": 4,
}
expected = [
[
("column", 0),
("end_column", 4),
("end_line", 1),
("line", 1),
("message", "Line too long (1/2)"),
("message-id", "C0301"),
("module", "0123"),
("obj", ""),
("path", "0123"),
("symbol", "line-too-long"),
("type", "convention"),
]
]
report = get_linter_result(score=False, message=message)
def test_simple_json_output_no_score() -> None:
report = get_linter_result(score=False)
assert len(report) == 1
report_result = [sorted(report[0].items(), key=lambda item: item[0])]
assert report_result == expected
assert report_result == expected_result


def get_linter_result(score: bool, message: Dict[str, Any]) -> List[Dict[str, Any]]:
def get_linter_result(score: bool) -> List[Dict[str, Any]]:
output = StringIO()
reporter = JSONReporter(output)
linter = PyLinter(reporter=reporter)
Expand All @@ -96,13 +56,7 @@ def get_linter_result(score: bool, message: Dict[str, Any]) -> List[Dict[str, An
linter.config.score = score
linter.open()
linter.set_current_module("0123")
linter.add_message(
message["msg"],
line=message["line"],
args=message["args"],
end_lineno=message["end_line"],
end_col_offset=message["end_column"],
)
linter.add_message("line-too-long", line=1, args=(1, 2))
# we call those methods because we didn't actually run the checkers
if score:
reporter.display_reports(EvaluationSection(expected_score_message))
Expand Down
4 changes: 0 additions & 4 deletions tests/unittest_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ def test_multi_format_output(tmp_path):
' "obj": "",\n'
' "line": 1,\n'
' "column": 0,\n'
' "end_line": null,\n'
' "end_column": null,\n'
f' "path": {escaped_source_file},\n'
' "symbol": "missing-module-docstring",\n'
' "message": "Missing module docstring",\n'
Expand All @@ -233,8 +231,6 @@ def test_multi_format_output(tmp_path):
' "obj": "",\n'
' "line": 1,\n'
' "column": 0,\n'
' "end_line": null,\n'
' "end_column": null,\n'
f' "path": {escaped_source_file},\n'
' "symbol": "line-too-long",\n'
' "message": "Line too long (1/2)",\n'
Expand Down

0 comments on commit 6e91225

Please sign in to comment.