Skip to content

Commit 0fa04d9

Browse files
authored
Merge pull request #13 from guilhermesimoes/highlight-tokens
Highlight text token if available
2 parents 931d61a + ca7d04e commit 0fa04d9

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

linter.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"""This module exports the Ruby plugin class."""
1313

1414
from SublimeLinter.lint import RubyLinter
15+
import re
1516

1617

1718
class Ruby(RubyLinter):
@@ -39,4 +40,35 @@ def split_match(self, match):
3940
if match.group('file') != '-':
4041
match = None
4142

42-
return super().split_match(match)
43+
match, line, col, error, warning, message, _ = super().split_match(match)
44+
near = self.search_token(message)
45+
46+
return match, line, col, error, warning, message, near
47+
48+
def search_token(self, message):
49+
"""Search text token to be highlighted."""
50+
51+
# First search for variable name enclosed in quotes
52+
m = re.search("(?<=`).*(?=')", message)
53+
54+
# Then search for variable name following a dash
55+
if m is None:
56+
m = re.search('(?<= - )\S+', message)
57+
58+
# Then search for mismatched indentation
59+
if m is None:
60+
m = re.search("(?<=mismatched indentations at ')end", message)
61+
62+
# Then search for equal operator in conditional
63+
if m is None:
64+
m = re.search('(?<=found )=(?= in conditional)', message)
65+
66+
# Then search for use of operator in void context
67+
if m is None:
68+
m = re.search('\S+(?= in void context)', message)
69+
70+
# Then search for END in method
71+
if m is None:
72+
m = re.search('END(?= in method)', message)
73+
74+
return m.group(0) if m else None

0 commit comments

Comments
 (0)