-
Notifications
You must be signed in to change notification settings - Fork 9
/
linter.py
78 lines (58 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
70
71
72
73
74
75
76
77
78
#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by Aparajita Fishman
# Copyright (c) 2015-2016 The SublimeLinter Community
# Copyright (c) 2013-2014 Aparajita Fishman
#
# License: MIT
#
"""This module exports the Ruby plugin class."""
from SublimeLinter.lint import RubyLinter
import re
class Ruby(RubyLinter):
"""Provides an interface to ruby -wc."""
defaults = {
'selector': 'source.ruby - text.html'
}
cmd = 'ruby -wc'
regex = (
r'^(?P<file>.+?):(?P<line>\d+): (?:(?P<error>.*?error)|(?P<warning>warning))[,:] (?P<message>[^\r\n]+)\r?\n'
r'(?:^[^\r\n]+\r?\n^(?P<col>.*?)\^)?'
)
multiline = True
comment_re = r'\s*#'
on_stderr = None
def split_match(self, match):
"""
Return the components of the match.
We override this because unrelated library files can throw errors,
and we only want errors from the linted file.
"""
if match:
if match.group('file') != '-':
match = None
match, line, col, error, warning, message, _ = super().split_match(match)
near = self.search_token(message)
return match, line, col, error, warning, message, near
def search_token(self, message):
"""Search text token to be highlighted."""
# First search for variable name enclosed in quotes
m = re.search("(?<=`).*(?=')", message)
# Then search for variable name following a dash
if m is None:
m = re.search('(?<= - )\S+', message)
# Then search for mismatched indentation
if m is None:
m = re.search("(?<=mismatched indentations at ')end", message)
# Then search for equal operator in conditional
if m is None:
m = re.search('(?<=found )=(?= in conditional)', message)
# Then search for use of operator in void context
if m is None:
m = re.search('\S+(?= in void context)', message)
# Then search for END in method
if m is None:
m = re.search('END(?= in method)', message)
return m.group(0) if m else None