Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for --show-column-numbers output #20

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"""
orsinium marked this conversation as resolved.
Show resolved Hide resolved
(?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
Loading