From 2f3dc23e1bc24b74c2673ecaf167c4bfa776a71a Mon Sep 17 00:00:00 2001 From: Daniel Rice Date: Sun, 19 Nov 2023 15:35:45 -0700 Subject: [PATCH 1/2] feat: Add support for --show-column-numbers output --- mypy_baseline/_error.py | 11 ++++++++++- tests/test_error.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mypy_baseline/_error.py b/mypy_baseline/_error.py index 5c50843..cb0c552 100644 --- a/mypy_baseline/_error.py +++ b/mypy_baseline/_error.py @@ -20,6 +20,15 @@ (?:\s\s\[(?P[a-z-]+)\])? \s* """, re.VERBOSE | re.MULTILINE) +REX_LINE_COLUMN = re.compile(r""" + (?P.+\.pyi?): + (?P[0-9]+): + (?P[0-9]+):\s + (?P[a-z]+):\s + (?P.+?) + (?:\s\s\[(?P[a-z-]+)\])? + \s* +""", re.VERBOSE | re.MULTILINE) REX_LINE_NBQA = re.compile(r""" (?P.+\.ipynb:cell_[0-9]+): (?P[0-9]+):\s @@ -44,7 +53,7 @@ class Error: @classmethod def new(self, line: str) -> Error | None: line = _remove_color_codes(line) - match = REX_LINE.fullmatch(line) or REX_LINE_NBQA.fullmatch(line) + match = REX_LINE.fullmatch(line) or REX_LINE_NBQA.fullmatch(line) or REX_LINE_COLUMN.fullmatch(line) if match is None: return None return Error(line, match) diff --git a/tests/test_error.py b/tests/test_error.py index ae9efd1..45b213c 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -46,3 +46,18 @@ def test_line3_parse(): assert e.message == 'This violates the Liskov substitution principle' assert e.category == 'note' assert e.get_clean_line(Config()) == LINE3EXP + +# --show-column-numbers files +LINE4 = 'my_project/api/views.py:10:42: note: This violates the Liskov substitution principle\r\n' # noqa +LINE4EXP = 'my_project/api/views.py:0: note: This violates the Liskov substitution principle' # noqa + + +def test_line4_parse(): + e = Error.new(LINE4) + assert e is not None + assert e.path.parts == ('my_project', 'api', 'views.py') + assert e.line_number == 10 + assert e.severity == 'note' + assert e.message == 'This violates the Liskov substitution principle' + assert e.category == 'note' + assert e.get_clean_line(Config()) == LINE4EXP From 65737bf5a3a01e82523ff45f95af84f5c40d6eab Mon Sep 17 00:00:00 2001 From: Daniel Rice Date: Fri, 1 Dec 2023 19:36:20 -0700 Subject: [PATCH 2/2] use single regex pattern --- mypy_baseline/_error.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mypy_baseline/_error.py b/mypy_baseline/_error.py index cb0c552..72aa6cf 100644 --- a/mypy_baseline/_error.py +++ b/mypy_baseline/_error.py @@ -20,10 +20,9 @@ (?:\s\s\[(?P[a-z-]+)\])? \s* """, re.VERBOSE | re.MULTILINE) -REX_LINE_COLUMN = re.compile(r""" +REX_LINE = re.compile(r""" (?P.+\.pyi?): - (?P[0-9]+): - (?P[0-9]+):\s + (?P[0-9]+):(?:[0-9]+:)?\s (?P[a-z]+):\s (?P.+?) (?:\s\s\[(?P[a-z-]+)\])? @@ -53,7 +52,7 @@ class Error: @classmethod def new(self, line: str) -> Error | None: line = _remove_color_codes(line) - match = REX_LINE.fullmatch(line) or REX_LINE_NBQA.fullmatch(line) or REX_LINE_COLUMN.fullmatch(line) + match = REX_LINE.fullmatch(line) or REX_LINE_NBQA.fullmatch(line) if match is None: return None return Error(line, match)