]> git.lizzy.rs Git - micro.git/blobdiff - runtime/plugins/linter/linter.lua
alphabetically order linters, add shell linter
[micro.git] / runtime / plugins / linter / linter.lua
index 9c68b97d8c379954cfe0803e3f6f0d1f1e938a9a..e1ec97732a2ae4d7e5bdf7570780fb1ba9171fcb 100644 (file)
@@ -12,35 +12,46 @@ end
 function runLinter()
     local ft = CurView().Buf:FileType()
     local file = CurView().Buf.Path
-    local devnull = "/dev/null"
-    local temp = os.getenv("TMPDIR")
+    local dir = DirectoryName(file)
     if OS == "windows" then
         devnull = "NUL"
-        temp = os.getenv("TEMP")
+    else
+        devnull = "/dev/null"
     end
-    if ft == "go" then
+
+    if ft == "c" then
+        lint("gcc", "gcc", {"-fsyntax-only", "-Wall", "-Wextra", file}, "%f:%l:%d+:.+: %m")
+    elseif ft == "c++" then
+        lint("gcc", "gcc", {"-fsyntax-only","-std=c++14", "-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 == "go" then
         lint("gobuild", "go", {"build", "-o", devnull}, "%f:%l: %m")
-        lint("golint", "golint", {CurView().Buf.Path}, "%f:%l:%d+: %m")
+        lint("golint", "golint", {file}, "%f:%l:%d+: %m")
+    elseif ft == "java" then
+        lint("javac", "javac", {"-d", dir, file}, "%f:%l: error: %m")
+    elseif ft == "javascript" then
+        lint("jshint", "jshint", {file}, "%f: line %l,.+, %m")
+    elseif string.match(ft, "literate") then
+        lint("literate", "lit", {"-c", file}, "%f:%l:%m")
     elseif ft == "lua" then
         lint("luacheck", "luacheck", {"--no-color", file}, "%f:%l:%d+: %m")
+    elseif ft == "nim" then
+        lint("nim", "nim", {"check", "--listFullPaths", "--stdout", "--hints:off", 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 == "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 == "swift" then
+    elseif ft == "shell" then
+        lint("shfmt", "shfmt", {file}, "%f:%l:%d+: %m")
+    elseif ft == "swift" and OS == "darwin" then
         lint("switfc", "xcrun", {"swiftc", 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")
-    elseif ft == "nim" then
-        lint("nim", "nim", {"check", "--listFullPaths", "--stdout", "--hints:off", file}, "%f\\(%l, %d\\) .+: %m")
+    elseif ft == "swift" and OS == "linux" then
+        lint("switfc", "swiftc", {file}, "%f:%l:%d+:.+: %m")
+    elseif ft == "yaml" then
+        lint("yaml", "yamllint", {"--format", "parsable", file}, "%f:%l:%d+:.+ %m")
     end
 end
 
@@ -66,7 +77,6 @@ function onExit(output, linter, errorformat)
         -- Trim whitespace
         line = line:match("^%s*(.+)%s*$")
         if string.find(line, regex) then
-            print(regex)
             local file, line, msg = string.match(line, regex)
             if basename(CurView().Buf.Path) == basename(file) then
                 CurView():GutterMessage(linter, tonumber(line), msg, 2)
@@ -85,6 +95,10 @@ function split(str, sep)
 end
 
 function basename(file)
-    local name = string.gsub(file, "(.*/)(.*)", "%2")
+    local sep = "/"
+    if OS == "windows" then
+        sep = "\\"
+    end
+    local name = string.gsub(file, "(.*" .. sep .. ")(.*)", "%2")
     return name
 end