Skip to content

Commit fdb1a5d

Browse files
committed
Showcase: Register two linters
1 parent 11460a4 commit fdb1a5d

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

linter.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,43 @@
1010

1111
"""This module exports the Clang plugin class."""
1212

13-
from SublimeLinter.lint import Linter, util
13+
import re
14+
from SublimeLinter.lint import Linter
1415

1516

16-
class Clang(Linter):
17-
"""Provides an interface to clang."""
17+
OUTPUT_RE = re.compile(
18+
r'<stdin>:(?P<line>\d+):'
19+
r'((?P<col>\d*): )?' # column number, colon and space are only applicable for single line messages
20+
# several lines of anything followed by
21+
# either error/warning/note or newline (= irrelevant backtrace content)
22+
# (lazy quantifiers so we don’t skip what we seek)
23+
r'(.*?((?P<error>error)|(?P<warning>warning|note)|\r?\n))+?'
24+
r': (?P<message>.+)', # match the remaining content of the current line for output
25+
re.MULTILINE
26+
)
1827

19-
regex = (
20-
r'<stdin>:(?P<line>\d+):'
21-
r'((?P<col>\d*): )?' # column number, colon and space are only applicable for single line messages
22-
# several lines of anything followed by
23-
# either error/warning/note or newline (= irrelevant backtrace content)
24-
# (lazy quantifiers so we don’t skip what we seek)
25-
r'(.*?((?P<error>error)|(?P<warning>warning|note)|\r?\n))+?'
26-
r': (?P<message>.+)' # match the remaining content of the current line for output
27-
)
28-
29-
multiline = True
3028

29+
class clangc(Linter):
30+
cmd = 'clang -fsyntax-only -fno-caret-diagnostics ${args} -'
3131
defaults = {
32-
'selector': 'source.c, source.c++',
32+
'selector': 'source.c',
3333
'-Wall': True,
3434
'-I +': [],
35-
'-x': None
35+
'-x': 'c'
3636
}
37-
37+
regex = OUTPUT_RE
38+
multiline = True
3839
on_stderr = None
3940

40-
def cmd(self):
41-
"""Return the command line to execute."""
42-
43-
cmd = 'clang -fsyntax-only -fno-caret-diagnostics ${args} -'
44-
45-
settings = self.get_view_settings()
46-
47-
# If not set by the user apply magic
48-
if settings['x'] is None:
49-
syntax = util.get_syntax(self.view)
50-
if syntax in ['c', 'c improved']:
51-
settings['x'] = 'c'
52-
elif syntax in ['c++', 'c++11']:
53-
settings['x'] = 'c++'
5441

55-
return cmd
42+
class clangcplus(Linter):
43+
cmd = 'clang -fsyntax-only -fno-caret-diagnostics ${args} -'
44+
defaults = {
45+
'selector': 'source.c++',
46+
'-Wall': True,
47+
'-I +': [],
48+
'-x': 'c++'
49+
}
50+
regex = OUTPUT_RE
51+
multiline = True
52+
on_stderr = None

0 commit comments

Comments
 (0)