vis-lint

vis plugin for linting code
git clone anongit@rnpnr.xyz:vis-lint.git
Log | Files | Refs | Feed | README | LICENSE

Commit: f8f490f3fe2072eb01fa545a4e9613f099665d7a
Parent: e3d0bfe8a50a139bf4de1fc5e80775980fce8e5c
Author: Hugo O. Rivera
Date:   Sun, 16 Apr 2023 09:32:25 -0600

More output and isolate code in run_actions_on_file function

Diffstat:
Minit.lua | 42++++++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/init.lua b/init.lua @@ -1,21 +1,35 @@ -vis:command_register("lint", function() - local linters = {} - linters["bash"] = "shellcheck -" - linters["lua"] = "luacheck --no-color -" - linters["man"] = "mandoc -T lint" +linters = {} +linters["bash"] = {"shellcheck -"} +linters["json"] = {"jq"} +linters["lua"] = {"luacheck --no-color -"} +linters["man"] = {"mandoc -T lint"} +linters["python"] = {"ruff", "mypy --strict"} - local cmd = linters[vis.win.syntax] - if cmd == nil then - vis:info(vis.win.syntax .. ": linter not defined") +-- Clear vis:message window before running? +run_actions_on_file = function(action, actions, file) + local cmds = actions[vis.win.syntax] + if cmds == nil or #cmds == 0 then + vis:info(action .. " not defined for " .. vis.win.syntax) return false end + for i, cmd in ipairs(cmds) do + vis:message("$ " .. cmd .. "\n") + local _, ostr, estr = vis:pipe(file, {start = 0, finish = file.size}, cmd) - local file = vis.win.file - local _, ostr, estr = vis:pipe(file, {start = 0, finish = file.size}, cmd) - if estr then - vis:message(estr) - return false + if ostr == nil and estr == nil then + vis:message("[no output]") + else + vis:message((ostr or "") .. (estr or "")) + end + vis:message("\n") + + if estr then + return false + end end - vis:message(ostr) return true +end + +vis:command_register("lint", function(argv, force, win, selection, range) + return run_actions_on_file('linters', linters, win.file) end, "Lint the current file and display output in the message window")