-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlinter.py
64 lines (51 loc) · 1.91 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
#
# linter.py
# Linter for SublimeLinter4, a code checking framework for Sublime Text 3
#
# Written by Sergey Margaritov
# Copyright (c) 2013 Sergey Margaritov
#
# License: MIT
#
"""This module exports the scss-lint plugin linter class."""
import logging
import re
from SublimeLinter.lint import RubyLinter
logger = logging.getLogger('SublimeLinter.plugin.scsslint')
RULE_RE = r'^(\w+)'
class ScssLint(RubyLinter):
"""Provides an interface to the scss-lint executable."""
cmd = ('ruby', '-S', 'scss-lint', '${args}', '${file}')
regex = r'^.+?:(?P<line>\d+)(?::(?P<col>\d+))? (?:(?P<error>\[E\])|(?P<warning>\[W\])) (?P<message>[^`]*(?:`(?P<near>.+?)`)?.*)'
word_re = r'[^\s]+[\w]'
defaults = {
'selector': 'source.scss'
}
def reposition_match(self, line, col, m, vv):
text = vv.select_line(m.line)
rule_match = re.search(RULE_RE, m.message)
rule_name = rule_match.group() if rule_match else None
if col != None and m.near:
near = self.strip_quotes(m.near)
# PseudoElement rule return incorrect 'near' string
if rule_name == 'PseudoElement':
# return the same when 'near' is None
# linter.py:978
match = self.word_re.search(text) if self.word_re else None
if match:
start = match.start()
length = len(match.group())
else:
start = 1
length = len(text) - 1
return line, start, start + length
# SelectorFormat return column 1, which is incorrect
elif rule_name == 'SelectorFormat':
real_col = text.find(near)
if real_col >= 0 and real_col != col:
return super().reposition_match(line, real_col, m, vv)
if rule_name == 'Indentation':
match = re.search(r'^([\s\t]+)', text)
if match:
return line, 0, len(match.group())
return super().reposition_match(line, col, m, vv)