Add automatic linting for Go, Python, C, D, Java, Javascript, Lua

This commit is contained in:
Zachary Yedidia
2016-04-30 18:25:45 -04:00
parent 1668e91310
commit 3cbb23bfbe
2 changed files with 30 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"
"github.com/go-errors/errors"
"github.com/layeh/gopher-luar"
@@ -215,6 +216,7 @@ func main() {
messenger = new(Messenger)
view := NewView(buf)
L.SetGlobal("OS", luar.New(L, runtime.GOOS))
L.SetGlobal("view", luar.New(L, view))
L.SetGlobal("settings", luar.New(L, &settings))
L.SetGlobal("messenger", luar.New(L, messenger))

View File

@@ -1,13 +1,39 @@
function linter_onSave()
local ft = view.Buf.Filetype
local file = view.Buf.Path
local devnull = "/dev/null"
if OS == "windows" then
devnull = "NUL"
end
if ft == "Go" then
linter_lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
linter_lint("golint", "golint " .. view.Buf.Path, "%f:%l:%d+: %m")
elseif ft == "Lua" then
linter_lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
elseif ft == "Python" then
linter_lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
elseif ft == "C" then
linter_lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
elseif ft == "D" then
linter_lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
elseif ft == "Java" then
linter_lint("javac", "javac " .. file, "%f:%l: error: %m")
elseif ft == "JavaScript" then
linter_lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
end
end
function linter_lint(linter, cmd, errorformat)
view:ClearGutterMessages(linter)
local handle = io.popen(cmd)
local handle = io.popen("(" .. cmd .. ")" .. " 2>&1")
local lines = linter_split(handle:read("*a"), "\n")
handle:close()
messenger:Message(view.Buf.Path)
local regex = errorformat:gsub("%%f", "(.+)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")
for _,line in ipairs(lines) do
-- Trim whitespace
line = line:match("^%s*(.+)%s*$")
if string.find(line, regex) then
local file, line, msg = string.match(line, regex)
if linter_basename(view.Buf.Path) == linter_basename(file) then