vis-lint

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

Commit: a19e9ac2bc5bdd01cf78129f9306729d5f3a443c
Parent: bfac856eb3454022a1644fb48f120e303abea316
Author: Randy Palamar
Date:   Sun, 14 May 2023 17:25:33 -0600

export lint and fix as functions

Diffstat:
MREADME.md | 8++++++++
Minit.lua | 12++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -50,3 +50,11 @@ A new filetype can be added as follows (`awkfix` is a hypothetical lint.fixers["awk"] = { "awkfix" } Note: if a default doesn't exist feel free to submit a patch adding it! + +### Running Fixers Before Writing + +The fixers can be run before saving a file using Vis' events: + + vis.events.subscribe(vis.events.FILE_SAVE_PRE, lint.fix) + +Note that if any fixer fails the file won't save (unless `:w!` was used). diff --git a/init.lua b/init.lua @@ -60,12 +60,20 @@ run_actions_on_file = function(action, actions, file, modify) return all_succeeded end +lint.lint = function(file) + return run_actions_on_file("linter", lint.linters, file, false) +end + +lint.fix = function(file) + return run_actions_on_file("fixer", lint.fixers, file, true) +end + vis:command_register("lint", function(argv, force, win, selection, range) - return run_actions_on_file("linters", lint.linters, win.file, false) + return lint.lint(win.file) end, "Lint the current file and display output in the message window") vis:command_register("fix", function(argv, force, win, selection, range) - return run_actions_on_file("fixers", lint.fixers, win.file, true) + return lint.fix(win.file) end, "Pipe the current file through defined fixers. Modifies the buffer.") return lint