-
Notifications
You must be signed in to change notification settings - Fork 2
/
linter.py
72 lines (63 loc) · 1.88 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
#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by Baptiste JAMIN
# Copyright (c) 2016 Baptiste JAMIN
#
# License: MIT
#
"""This module exports the 42Norminette plugin class."""
import shlex
from SublimeLinter.lint import Linter, persist, util
import sublime
import os
import string
import math
class Norminette(Linter):
"""Provides an interface to norminette."""
cmd = "norminette ${file_on_disk}"
tempfile_suffix = "-"
regex = r'''(?xi)
^^(?:(?P<error>Error)|(?P<warning>Warning)) # Error
# Norminette emits errors that pertain to the code as a whole,
# in which case there is no line/col information, so that
# part is optional.
(?:(.+?(?P<line>\d+)))?
(?:(.+?(?P<col2>\d+)))?
(?:\)\:\s*)?
(?:(?P<message>.+))
'''
line_col_base = (1, 0)
multiline = True
error_stream = util.STREAM_BOTH
defaults = {
'selector': 'source.c'
}
def split_match(self, match):
error = super().split_match(match)
if error["message"] and error["line"] is None:
error["line"] = 1
error["col2"] = 1
error["col"] = int(error["col2"])
return error
def reposition_match(self, line, col, m, vv):
col = int(m['col2'])
if col > 0:
content = vv.select_line(line)
c = 0
cr = 0
tab = 0
maxc = col
while cr < maxc and c < len(content):
if content[c] == '\t':
spaces = (4 - math.ceil(cr % 4))
col -= spaces
cr += spaces
tab = 1
c += 1
cr += 1
if tab == 0:
col = col - 1
col = max(min(col, len(content) - 1), 0)
return super().reposition_match(line, col, m, vv)