-
Notifications
You must be signed in to change notification settings - Fork 7
/
linter.lua
46 lines (39 loc) · 1.43 KB
/
linter.lua
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
-- lite-xl 1.16
-- linter compatibility module for lint+
-- this module simply defines a linter.add_language function for compatibility
-- with the existing linter module.
-- note that linter modules are not capable of using all of lint+'s
-- functionality: namely, they cannot use the four available levels of severity.
-- all messages will have the warning severity level.
local lintplus = require "plugins.lintplus"
local linter = {}
local name_counter = 0
function linter.add_language(t)
lintplus.add("compat.linter"..name_counter) {
filename = t.file_patterns,
procedure = {
command = lintplus.command(
t.command
:gsub("%$FILENAME", "$filename")
:gsub("%$ARGS", table.concat(t.args, ' '))
),
-- can't use the lintplus interpreter simply because it doesn't work
-- exactly as linter does
interpreter = function (filename, line)
local yielded_message = false
return function ()
if yielded_message then return nil end
local ln, column, message = line:match(t.warning_pattern)
if ln then
-- we return the original filename to show all warnings
-- because... say it with me... that's how linter works!!
yielded_message = true
return filename, tonumber(ln), tonumber(column), "warning", message
end
end
end,
},
}
name_counter = name_counter + 1
end
return linter