-
Notifications
You must be signed in to change notification settings - Fork 2
/
linter.py
59 lines (48 loc) · 2.23 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
import os
from SublimeLinter.lint import RubyLinter
class StandardRB(RubyLinter):
defaults = {
'selector': 'source.ruby - text.html - text.haml'
}
regex = (
r'^.+?:(?P<line>\d+):(?P<col>\d+): '
r'(:?(?P<warning>[RCW])|(?P<error>[EF])): '
r'(?P<message>.+)'
)
def cmd(self):
"""Build command, using STDIN if a file path can be determined."""
settings = self.settings
command = ['ruby', '-S']
if settings.get('use_bundle_exec', False):
command.extend(['bundle', 'exec'])
command.extend(['standardrb', '--format', 'emacs'])
# Set tempfile_suffix so by default a tempfile is passed onto standard:
self.tempfile_suffix = 'rb'
path = self.filename
if not path:
# File is unsaved, and by default unsaved files use the default
# standard config because they do not technically belong to a
# folder that might contain a custom .standard.yml. This means the
# lint results may not match the rules for the currently open
# project.
#
# If the current window has open folders then we can use the
# first open folder as a best-guess for the current projects
# root folder - we can then pretend that this unsaved file is
# inside this root folder, and standard will pick up on any
# config file if it does exist:
folders = self.view.window().folders()
if folders:
path = os.path.join(folders[0], 'untitled.rb')
if path:
# With this path we can instead pass the file contents in via STDIN
# and then tell standard to use this path (to search for config
# files and to use for matching against configured paths - i.e. for
# inheritance, inclusions and exclusions).
#
# The 'force-exclusion' overrides standard's behavior of ignoring
# global excludes when the file path is explicitly provided:
command += ['--force-exclusion', '--stdin', path]
# Ensure the files contents are passed in via STDIN:
self.tempfile_suffix = None
return command