Skip to content

Commit

Permalink
Change spacing around report summary
Browse files Browse the repository at this point in the history
Before this change an empty line would be printed above the summary when
there were no new errors, and no empty line would be printed when there
were errors.

This change reverses that. An empty line is printed to separate the
summary from the new errors only if there are new errors.
  • Loading branch information
meshy committed Jan 3, 2024
1 parent e4bc36a commit c209c3e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
6 changes: 4 additions & 2 deletions mypy_json_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def __init__(self, _write: Callable[[str], Any] = sys.stdout.write) -> None:

def write_report(self, diff: DiffReport) -> None:
new_errors = "\n".join(diff.error_lines)
self.write(new_errors + "\n")
if new_errors:
self.write(new_errors + "\n\n")
self.write(f"Fixed errors: {diff.num_fixed_errors}\n")
self.write(f"New errors: {diff.num_new_errors}\n")
self.write(f"Total errors: {diff.total_errors}\n")
Expand All @@ -282,7 +283,8 @@ def __init__(self, _write: Callable[[str], Any] = sys.stdout.write) -> None:

def write_report(self, diff: DiffReport) -> None:
new_errors = "\n".join([self._format_line(line) for line in diff.error_lines])
self.write(new_errors + "\n")
if new_errors:
self.write(new_errors + "\n\n")

fixed_color = self._BOLD_RED if diff.num_fixed_errors else self._GREEN
error_color = self._BOLD_RED if diff.num_new_errors else self._GREEN
Expand Down
20 changes: 7 additions & 13 deletions tests/test_mypy_json_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,7 @@ def test_no_errors(self) -> None:
)
)

assert messages == [
"\n",
"Fixed errors: 0\n",
"New errors: 0\n",
"Total errors: 0\n",
]
assert messages == ["Fixed errors: 0\n", "New errors: 0\n", "Total errors: 0\n"]

def test_with_errors(self) -> None:
messages: List[str] = []
Expand All @@ -353,7 +348,7 @@ def test_with_errors(self) -> None:
)

assert messages == [
"file.py:8: error: An example type error\n",
"file.py:8: error: An example type error\n\n",
"Fixed errors: 0\n",
"New errors: 1\n",
"Total errors: 2\n",
Expand All @@ -372,7 +367,6 @@ def test_no_errors(self) -> None:
)

assert messages == [
"\n",
"\x1b[32mFixed errors: 0\n\x1b[0m",
"\x1b[32mNew errors: 0\n\x1b[0m",
"\x1b[1mTotal errors: 0\n\x1b[0m",
Expand All @@ -392,7 +386,7 @@ def test_with_error(self) -> None:
)

assert messages == [
"file.py:8:\x1b[31;1m error: \x1b[0mAn example type error\n",
"file.py:8:\x1b[31;1m error: \x1b[0mAn example type error\n\n",
"\x1b[31;1mFixed errors: 1\n\x1b[0m",
"\x1b[31;1mNew errors: 1\n\x1b[0m",
"\x1b[1mTotal errors: 2\n\x1b[0m",
Expand All @@ -414,7 +408,7 @@ def test_with_error_containing_braces(self) -> None:
)

assert messages == [
"file.py:8:\x1b[31;1m error: \x1b[0mContains [braces] but not an error code\n",
"file.py:8:\x1b[31;1m error: \x1b[0mContains [braces] but not an error code\n\n",
"\x1b[31;1mFixed errors: 1\n\x1b[0m",
"\x1b[31;1mNew errors: 1\n\x1b[0m",
"\x1b[1mTotal errors: 2\n\x1b[0m",
Expand All @@ -436,7 +430,7 @@ def test_unclosed_error_code(self) -> None:
)

assert messages == [
"file.py:8:\x1b[31;1m error: \x1b[0mResembles error code but [is-not-closed\n",
"file.py:8:\x1b[31;1m error: \x1b[0mResembles error code but [is-not-closed\n\n",
"\x1b[31;1mFixed errors: 1\n\x1b[0m",
"\x1b[31;1mNew errors: 1\n\x1b[0m",
"\x1b[1mTotal errors: 2\n\x1b[0m",
Expand All @@ -456,7 +450,7 @@ def test_with_error_with_code(self) -> None:
)

assert messages == [
"file.py:8:\x1b[31;1m error: \x1b[0mAn example type error\x1b[33m [error-code]\x1b[0m\n",
"file.py:8:\x1b[31;1m error: \x1b[0mAn example type error\x1b[33m [error-code]\x1b[0m\n\n",
"\x1b[32mFixed errors: 0\n\x1b[0m",
"\x1b[31;1mNew errors: 1\n\x1b[0m",
"\x1b[1mTotal errors: 2\n\x1b[0m",
Expand All @@ -476,7 +470,7 @@ def test_with_note(self) -> None:
)

assert messages == [
"file.py:8:\x1b[34m note: \x1b[0mAn example note\n",
"file.py:8:\x1b[34m note: \x1b[0mAn example note\n\n",
"\x1b[31;1mFixed errors: 1\n\x1b[0m",
"\x1b[31;1mNew errors: 1\n\x1b[0m",
"\x1b[1mTotal errors: 2\n\x1b[0m",
Expand Down

0 comments on commit c209c3e

Please sign in to comment.