-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlinter.py
39 lines (31 loc) · 1.27 KB
/
linter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from SublimeLinter.lint import PythonLinter
import re
class Pyflakes(PythonLinter):
cmd = 'pyflakes'
regex = r'''(?x)
^(?P<filename>.+?):(?P<line>\d+):((?P<col>\d+):?)?\s
# The rest of the line is the error message.
# Within that, capture anything within single quotes as `near`.
(?P<message>[^\'\n\r]*(?P<near>\'.+?\')?.*)
'''
multiline = True
# stderr has all syntax errors, parse it via our regex
on_stderr = None
defaults = {
'selector': 'source.python'
}
def reposition_match(self, line, col, match, vv):
if 'imported but unused' in match.message:
# Consider:
# from foo import bar
# import foo.bar
# In both cases `pyflakes` reports `'foo.bar' ... unused`.
import_id = re.escape(match.near[1:-1]) # unquote
last_part = import_id.split('.')[-1]
# So we match either `bar` or `foo.bar` against the line content
text = vv.select_line(line)
pattern = r"\s({}|{})".format(last_part, import_id)
re_match = re.search(pattern, text)
if re_match:
return line, re_match.start(1), re_match.end(1)
return super().reposition_match(line, col, match, vv)