1 if GetOption("linter") == nil then
2 AddOption("linter", true)
5 MakeCommand("lint", "linter.lintCommand", 0)
13 local ft = CurView().Buf:FileType()
14 local file = CurView().Buf.Path
15 local devnull = "/dev/null"
16 if OS == "windows" then
20 lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
21 lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
22 elseif ft == "lua" then
23 lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
24 elseif ft == "python" then
25 lint("pyflakes", "pyflakes " .. file, "%f:%l:.-:? %m")
27 lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
29 lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
30 elseif ft == "java" then
31 lint("javac", "javac " .. file, "%f:%l: error: %m")
32 elseif ft == "javascript" then
33 lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
38 if GetOption("linter") then
41 CurView():ClearAllGutterMessages()
45 function lint(linter, cmd, errorformat)
46 CurView():ClearGutterMessages(linter)
48 JobStart(cmd, "", "", "linter.onExit", linter, errorformat)
51 function onExit(output, linter, errorformat)
52 local lines = split(output, "\n")
54 local regex = errorformat:gsub("%%f", "(..-)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")
55 for _,line in ipairs(lines) do
57 line = line:match("^%s*(.+)%s*$")
58 if string.find(line, regex) then
59 local file, line, msg = string.match(line, regex)
60 if basename(CurView().Buf.Path) == basename(file) then
61 CurView():GutterMessage(linter, tonumber(line), msg, 2)
67 function split(str, sep)
69 local regex = ("([^%s]+)"):format(sep)
70 for each in str:gmatch(regex) do
71 table.insert(result, each)
76 function basename(file)
77 local name = string.gsub(file, "(.*/)(.*)", "%2")