forked from SublimeLinter/SublimeLinter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linter.py
69 lines (52 loc) · 2.14 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import platform
import tempfile
from SublimeLinter.lint import Linter
if platform.system() == "Windows":
GROOVY_BINARY = 'groovyc.bat'
CLASSPATH_DIVIDER = ';'
else:
GROOVY_BINARY = "groovyc"
CLASSPATH_DIVIDER = ':'
class Groovy(Linter):
tempfile_suffix = "-"
regex = r'''(?sx)(.*?:\ # Filepath part
\d+:\ # Line part, we ignore it as we have it later
(?P<message>.*?)\s* # Error message till @
@\ line\ (?P<line>\d+),\ column\ (?P<col>\d+)\. # line and column, ends with dot
''' \
'{}'.format(os.linesep) +\
r'''\s*(?P<code>.*?)\n # 2line - code snippet of error, it has to end with unix newline
''' \
r'|.*) # The last resort match - if we do not match error, match anything to silence info from SL'
multiline = True
defaults = {
'classpath': None,
'sourcepath': None,
'selector': 'source.groovy',
}
on_stderr = None
def cmd(self):
cmd = (GROOVY_BINARY,)
settings = self.get_view_settings()
# pylint: disable=attribute-defined-outside-init
self._tempdir = tempfile.TemporaryDirectory(prefix="sublimelinter-contrib-groovyc-target-")
classpaths = []
classpaths.append(settings.get('classpath') or '')
classpaths.append(self._tempdir.name)
classpath_str = '"{}'.format(CLASSPATH_DIVIDER) + '{}"'.format(CLASSPATH_DIVIDER.join(classpaths))
cmd += ('-classpath', classpath_str)
for opt in ('sourcepath',):
value = settings.get(opt)
if value is not None:
cmd += ('--{}'.format(opt), '"{}"'.format(value),)
cmd += ('-d', '"{}"'.format(self._tempdir.name))
return cmd
def run(self, cmd, code=None):
with self._tempdir:
return super().run(cmd, code)
def split_match(self, match):
match, line, col, error, warning, message, near = super().split_match(match)
if line is None:
return match, 0, 0, None, None, None, None
return match, line, col, error, warning, message, near