AddOption("linter", true)
end
-function onSave()
+MakeCommand("lint", "linter.lintCommand", 0)
+
+function lintCommand()
+ CurView():Save(false)
+ runLinter()
+end
+
+function runLinter()
+ local ft = CurView().Buf:FileType()
+ local file = CurView().Buf.Path
+ local devnull = "/dev/null"
+ local temp = os.getenv("TMPDIR")
+ if OS == "windows" then
+ devnull = "NUL"
+ temp = os.getenv("TEMP")
+ end
+ if ft == "go" then
+ lint("gobuild", "go", {"build", "-o", devnull}, "%f:%l: %m")
+ lint("golint", "golint", {CurView().Buf.Path}, "%f:%l:%d+: %m")
+ elseif ft == "lua" then
+ lint("luacheck", "luacheck", {"--no-color", file}, "%f:%l:%d+: %m")
+ elseif ft == "python" then
+ lint("pyflakes", "pyflakes", {file}, "%f:%l:.-:? %m")
+ lint("mypy", "mypy", {file}, "%f:%l: %m")
+ lint("pylint", "pylint", {"--output-format=parseable", "--reports=no", file}, "%f:%l: %m")
+ elseif ft == "c" then
+ lint("gcc", "gcc", {"-fsyntax-only", "-Wall", "-Wextra", file}, "%f:%l:%d+:.+: %m")
+ elseif ft == "Objective-C" then
+ lint("clang", "xcrun", {"clang", "-fsyntax-only", "-Wall", "-Wextra", file}, "%f:%l:%d+:.+: %m")
+ elseif ft == "d" then
+ lint("dmd", "dmd", {"-color=off", "-o-", "-w", "-wi", "-c", file}, "%f%(%l%):.+: %m")
+ elseif ft == "java" then
+ lint("javac", "javac", {"-d", temp, file}, "%f:%l: error: %m")
+ elseif ft == "javascript" then
+ lint("jshint", "jshint", {file}, "%f: line %l,.+, %m")
+ end
+end
+
+function onSave(view)
if GetOption("linter") then
- local ft = CurView().Buf.FileType
- local file = CurView().Buf.Path
- local devnull = "/dev/null"
- if OS == "windows" then
- devnull = "NUL"
- end
- if ft == "Go" then
- lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
- lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
- elseif ft == "Lua" then
- lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
- elseif ft == "Python" then
- lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
- elseif ft == "C" then
- lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
- elseif ft == "D" then
- lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
- elseif ft == "Java" then
- lint("javac", "javac " .. file, "%f:%l: error: %m")
- elseif ft == "JavaScript" then
- lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
- end
+ runLinter()
else
CurView():ClearAllGutterMessages()
end
end
-function lint(linter, cmd, errorformat)
+function lint(linter, cmd, args, errorformat)
CurView():ClearGutterMessages(linter)
- JobStart(cmd, "", "", "linter.onExit", linter, errorformat)
+ JobSpawn(cmd, args, "", "", "linter.onExit", linter, errorformat)
end
function onExit(output, linter, errorformat)
local lines = split(output, "\n")
- local regex = errorformat:gsub("%%f", "(.+)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")
+ local regex = errorformat:gsub("%%f", "(..-)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")
for _,line in ipairs(lines) do
-- Trim whitespace
line = line:match("^%s*(.+)%s*$")