Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b2de02

Browse files
authored
Merge pull request #57 from SublimeLinter/iteration
2 parents 351e90e + 5d5b1ad commit 5b2de02

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

linter.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import threading
2222
import getpass
2323

24-
from SublimeLinter.lint import LintMatch, PythonLinter
25-
from SublimeLinter.lint.linter import PermanentError
24+
from SublimeLinter.lint import LintMatch, PermanentError, PythonLinter
2625

2726

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

5453
regex = (
55-
r'^(?P<filename>.+?):(?P<line>\d+):((?P<col>\d+):)?\s*'
54+
r'^(?P<filename>.+?):'
55+
r'(?P<line>\d+|-1):((?P<col>\d+|-1):)?'
56+
r'((?P<end_line>\d+|-1):(?P<end_col>\d+|-1):)?\s*'
5657
r'(?P<error_type>[^:]+):\s(?P<message>.+?)(\s\s\[(?P<code>.+)\])?$'
5758
)
5859
line_col_base = (1, 1)
@@ -75,6 +76,7 @@ def cmd(self):
7576
cmd = [
7677
'mypy',
7778
'${args}',
79+
'--no-pretty',
7880
'--show-column-numbers',
7981
'--hide-error-context',
8082
'--no-error-summary',
@@ -141,6 +143,14 @@ def find_errors(self, output):
141143
previous['message'] += '\n{}'.format(error.message)
142144
continue
143145

146+
# mypy might report `-1` for unknown values.
147+
# Only `line` is mandatory within SublimeLinter
148+
if error.match.group('line') == "-1": # type: ignore[attr-defined]
149+
error['line'] = 0
150+
for group in ('col', 'end_line', 'end_col'):
151+
if error.match.group(group) == "-1": # type: ignore[attr-defined]
152+
error[group] = None
153+
144154
errors.append(error)
145155
yield from errors
146156

tests/test_regex.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ def test_matches(self):
4141
'col': None,
4242
'message': '"dict" is not subscriptable, use "typing.Dict" instead'})
4343

44+
self.assertMatch(
45+
'codespell_lib\\tests\\test_basic.py:518:5:518:13: error: Module has no attribute "mkfifo" [attr-defined]', {
46+
'line': 517,
47+
'col': 4,
48+
'end_line': 517,
49+
'end_col': 12,
50+
})
51+
52+
self.assertMatch(
53+
'codespell_lib\\tests\\test_basic.py:-1:-1:-1:-1: error: Module has no attribute "mkfifo" [attr-defined]', {
54+
'line': 0,
55+
'col': None,
56+
'end_line': None,
57+
'end_col': None,
58+
})
59+
4460
def test_tmp_files_that_have_no_file_extension(self):
4561
self.assertMatch(
4662
'/tmp/yoeai32h2:6:1: error: Cannot find module named \'PackageName.lib\'', {

0 commit comments

Comments
 (0)