-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlinter.py
78 lines (67 loc) · 2.65 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
70
71
72
73
74
75
76
77
78
import json
import re
import logging
from SublimeLinter.lint import NodeLinter
from SublimeLinter.lint import util
from SublimeLinter.lint.linter import LintMatch
logger = logging.getLogger('SublimeLinter.plugin.stylelint')
class Stylelint(NodeLinter):
cmd = 'stylelint --formatter json --stdin-filename ${file}'
on_stderr = None
error_stream = util.STREAM_BOTH
line_col_base = (1, 1)
crash_regex = re.compile(
r'^.*?\r?\n?\w*Error: (.*)',
re.MULTILINE
)
defaults = {
'selector': 'source.css - meta.attribute-with-value, source.sass, source.scss, source.less, source.sss' # noqa 501
}
def find_errors(self, output):
"""
Parse errors from linter's output.
We override this method to handle parsing stylelint crashes,
deprecations and other feedback about the config.
"""
data = None
match = self.crash_regex.match(output)
if match:
msg = "Stylelint crashed: %s" % match.group(1)
logger.warning(msg)
self.notify_failure()
try:
if output and not match:
data = json.loads(output)[0]
except Exception as e:
logger.warning(e)
self.notify_failure()
if data and 'invalidOptionWarnings' in data:
if data['invalidOptionWarnings'] != []:
self.notify_failure()
for option in data['invalidOptionWarnings']:
text = option['text']
logger.warning(text)
if data and 'deprecations' in data:
if data['deprecations'] != []:
self.notify_failure()
for option in data['deprecations']:
text = option['text']
logger.warning(text)
if data and 'warnings' in data:
for warning in data['warnings']:
line = warning['line'] - self.line_col_base[0]
col = warning['column'] - self.line_col_base[1]
end_line = warning['endLine'] - self.line_col_base[0] if 'endLine' in warning else None
end_col = warning['endColumn'] - self.line_col_base[1] if 'endColumn' in warning else None
text = warning['text'].replace('(' + warning['rule'] + ')', '')
text = text.rstrip()
yield LintMatch(
match=warning,
line=line,
col=col,
end_line=end_line,
end_col=end_col,
error_type=warning['severity'],
code=warning['rule'],
message=text
)