Skip to content

Commit

Permalink
Merge pull request #57 from SublimeLinter/iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Feb 6, 2023
2 parents 351e90e + 5d5b1ad commit 5b2de02
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
16 changes: 13 additions & 3 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import threading
import getpass

from SublimeLinter.lint import LintMatch, PythonLinter
from SublimeLinter.lint.linter import PermanentError
from SublimeLinter.lint import LintMatch, PermanentError, PythonLinter


MYPY = False
Expand Down Expand Up @@ -52,7 +51,9 @@ class Mypy(PythonLinter):
"""Provides an interface to mypy."""

regex = (
r'^(?P<filename>.+?):(?P<line>\d+):((?P<col>\d+):)?\s*'
r'^(?P<filename>.+?):'
r'(?P<line>\d+|-1):((?P<col>\d+|-1):)?'
r'((?P<end_line>\d+|-1):(?P<end_col>\d+|-1):)?\s*'
r'(?P<error_type>[^:]+):\s(?P<message>.+?)(\s\s\[(?P<code>.+)\])?$'
)
line_col_base = (1, 1)
Expand All @@ -75,6 +76,7 @@ def cmd(self):
cmd = [
'mypy',
'${args}',
'--no-pretty',
'--show-column-numbers',
'--hide-error-context',
'--no-error-summary',
Expand Down Expand Up @@ -141,6 +143,14 @@ def find_errors(self, output):
previous['message'] += '\n{}'.format(error.message)
continue

# mypy might report `-1` for unknown values.
# Only `line` is mandatory within SublimeLinter
if error.match.group('line') == "-1": # type: ignore[attr-defined]
error['line'] = 0
for group in ('col', 'end_line', 'end_col'):
if error.match.group(group) == "-1": # type: ignore[attr-defined]
error[group] = None

errors.append(error)
yield from errors

Expand Down
16 changes: 16 additions & 0 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ def test_matches(self):
'col': None,
'message': '"dict" is not subscriptable, use "typing.Dict" instead'})

self.assertMatch(
'codespell_lib\\tests\\test_basic.py:518:5:518:13: error: Module has no attribute "mkfifo" [attr-defined]', {
'line': 517,
'col': 4,
'end_line': 517,
'end_col': 12,
})

self.assertMatch(
'codespell_lib\\tests\\test_basic.py:-1:-1:-1:-1: error: Module has no attribute "mkfifo" [attr-defined]', {
'line': 0,
'col': None,
'end_line': None,
'end_col': None,
})

def test_tmp_files_that_have_no_file_extension(self):
self.assertMatch(
'/tmp/yoeai32h2:6:1: error: Cannot find module named \'PackageName.lib\'', {
Expand Down

0 comments on commit 5b2de02

Please sign in to comment.