vis-lint

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

Commit: de1edf89e4f64c7bb121525afaa7c7734ae13d89
Parent: 38cdd791e31c41040f5db020e4e5f3f07859da0b
Author: Randy Palamar
Date:   Sun, 14 May 2023 16:58:09 -0600

make linters and fixers configurable

Diffstat:
MREADME.md | 34+++++++++++++++++++++++++++++++++-
Minit.lua | 40+++++++++++++++++-----------------------
2 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/README.md b/README.md @@ -8,7 +8,7 @@ and display the output in the message window. Clone the repo to `$VIS_PATH/plugins` and then its sufficient to include the following in your `visrc.lua`: - require('plugins/vis-lint') + require("plugins/vis-lint") See [Plugins](https://github.com/martanne/vis/wiki/Plugins) on the Vis wiki for further details. @@ -18,3 +18,35 @@ wiki for further details. Type the following into the Vis command prompt: :lint + +## Configuration + +### Adding A Tool + +Additional tools for fixing and linting can be added as follows: + + local lint = require("plugins/vis-lint") + table.insert(lint.linters["python"], "pylint --from-stdin stdin_from_vis") + +Note: any added tools must read/write from `stdin`/`stdout`. Some +programs, like the above example, may need some non standard flags. You +can also try using `-` or `/dev/stdin` as the input parameter. + +### Overriding The Defaults + +The defaults can be also be overridden: + + lint.fixers["lua"] = { "cat" } + +Note that an equivalent in this case is just: + + lint.fixers["lua"] = {} + +### Adding New Filetypes + +A new filetype can be added as follows (`awkfix` is a hypothetical +`awk` fixer): + + lint.fixers["awk"] = { "awkfix" } + +Note: if a default doesn't exist feel free to submit a patch adding it! diff --git a/init.lua b/init.lua @@ -1,25 +1,17 @@ -linters = {} -linters["bash"] = {"shellcheck -"} -linters["json"] = {"jq"} -linters["lua"] = {"luacheck --no-color -"} -linters["man"] = {"mandoc -T lint"} -linters["python"] = { - "black --check -", - "isort --check -", - "pylint --from-stdin stdin_from_vis", - "flake8 -", - "ruff -", - -- The shell must support process substitution - -- Try setting vis' shell to "sh" with "set shell sh" - -- https://github.com/python/mypy/issues/12235 - "mypy <(cat)" -} -linters["rust"] = {"rustfmt --check", "clippy-driver -"} +local lint = {} -fixers = {} -fixers["json"] = {"jq -c"} -fixers["python"] = {"black -", "isort -", "ruff --fix -"} -fixers["rust"] = {"rustfmt"} +lint.linters = {} +lint.linters["bash"] = {"shellcheck -"} +lint.linters["json"] = {"jq"} +lint.linters["lua"] = {"luacheck --no-color -"} +lint.linters["man"] = {"mandoc -T lint"} +lint.linters["python"] = {"black --check -", "isort --check -"} +lint.linters["rust"] = {"rustfmt --check", "clippy-driver -"} + +lint.fixers = {} +lint.fixers["json"] = {"jq -c"} +lint.fixers["python"] = {"black -", "isort -"} +lint.fixers["rust"] = {"rustfmt"} -- Clear vis:message window before running? run_actions_on_file = function(action, actions, file, modify) @@ -69,9 +61,11 @@ run_actions_on_file = function(action, actions, file, modify) end vis:command_register("lint", function(argv, force, win, selection, range) - return run_actions_on_file('linters', linters, win.file, false) + return run_actions_on_file("linters", lint.linters, win.file, false) 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', fixers, win.file, true) + return run_actions_on_file("fixers", lint.fixers, win.file, true) end, "Pipe the current file through defined fixers. Modifies the buffer.") + +return lint