Skip to content

Commit 938b857

Browse files
authored
Merge pull request #78 from SublimeLinter/reposition-ws-errors
Reposition white-space errors
2 parents 50304c3 + a78cf34 commit 938b857

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

linter.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from SublimeLinter.lint import PythonLinter
2+
import re
3+
4+
CAPTURE_WS = re.compile('(\s+)')
25

36

47
class Flake8(PythonLinter):
@@ -47,3 +50,32 @@ def split_match(self, match):
4750
col = None
4851

4952
return match, line, col, error, warning, message, near
53+
54+
def reposition_match(self, line, col, m, virtual_view):
55+
"""Reposition white-space errors."""
56+
code = m.error or m.warning
57+
58+
if code in ('W291', 'W293'):
59+
txt = virtual_view.select_line(line).rstrip('\n')
60+
return (line, col, len(txt))
61+
62+
if code.startswith('E1'):
63+
return (line, 0, col)
64+
65+
if code.startswith('E2'):
66+
txt = virtual_view.select_line(line).rstrip('\n')
67+
match = CAPTURE_WS.match(txt[col:])
68+
if match is not None:
69+
length = len(match.group(1))
70+
return (line, col, col + length)
71+
72+
if code == 'E302':
73+
return line - 1, 0, 1
74+
75+
if code == 'E303':
76+
match = re.match('too many blank lines \((\d+)', m.message.strip())
77+
if match is not None:
78+
count = int(match.group(1))
79+
return (line - (count - 1), 0, count - 1)
80+
81+
return super().reposition_match(line, col, m, virtual_view)

0 commit comments

Comments
 (0)