Skip to content

Commit

Permalink
feat: Add support for --show-column-numbers output
Browse files Browse the repository at this point in the history
  • Loading branch information
drice committed Nov 19, 2023
1 parent b9c86ad commit 2f3dc23
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mypy_baseline/_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
(?:\s\s\[(?P<category>[a-z-]+)\])?
\s*
""", re.VERBOSE | re.MULTILINE)
REX_LINE_COLUMN = re.compile(r"""
(?P<path>.+\.pyi?):
(?P<lineno>[0-9]+):
(?P<columnno>[0-9]+):\s
(?P<severity>[a-z]+):\s
(?P<message>.+?)
(?:\s\s\[(?P<category>[a-z-]+)\])?
\s*
""", re.VERBOSE | re.MULTILINE)
REX_LINE_NBQA = re.compile(r"""
(?P<path>.+\.ipynb:cell_[0-9]+):
(?P<lineno>[0-9]+):\s
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2f3dc23

Please sign in to comment.