]> git.lizzy.rs Git - micro.git/blobdiff - runtime/plugins/linter/linter.lua
Make linter a default plugin once again
[micro.git] / runtime / plugins / linter / linter.lua
index 6cf07de73446771c56d9c36b9051624953d95799..9fb347f50b1931a877db2e429748c3ab41ca3b6f 100644 (file)
@@ -2,11 +2,15 @@ if GetOption("linter") == nil then
     AddOption("linter", true)
 end
 
-MakeCommand("lint", "linter.runLinter", 0)
+MakeCommand("lint", "linter.lintCommand", 0)
 
-function runLinter()
+function lintCommand()
     CurView():Save(false)
-    local ft = CurView().Buf.FileType
+    runLinter()
+end
+
+function runLinter()
+    local ft = CurView().Buf:FileType()
     local file = CurView().Buf.Path
     local devnull = "/dev/null"
     if OS == "windows" then
@@ -18,7 +22,7 @@ function runLinter()
     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("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
@@ -30,7 +34,7 @@ function runLinter()
     end
 end
 
-function onSave()
+function onSave(view)
     if GetOption("linter") then
         runLinter()
     else
@@ -47,7 +51,7 @@ 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*$")