1
0
Fork 0
dotfiles/home/config/nvim/plugins/nvim-lint.fnl

52 lines
2 KiB
Text
Raw Normal View History

(let [lint (require :lint)
diagnostic (require :nifoc.diagnostic)
augroup (vim.api.nvim_create_augroup :NifocLint {:clear true})
aucmd vim.api.nvim_create_autocmd]
2022-04-21 16:56:06 +00:00
;; Custom Linters
2022-04-19 16:07:34 +00:00
(set lint.linters.deadnix
{:cmd :deadnix
2022-05-12 20:19:52 +00:00
:stdin false
:args [:--output-format :json]
2022-04-19 16:07:34 +00:00
:stream :stdout
:ignore_exitcode false
:parser (fn [output]
(if (= output "") {}
(let [findings (vim.json.decode output)]
(vim.tbl_map (fn [result]
{:lnum (- result.line 1)
:end_lnum (- result.line 1)
:col (- result.column 1)
:end_col (- result.endColumn 1)
:severity vim.diagnostic.severity.HINT
:source :deadnix
:message result.message})
findings.results))))})
2022-04-21 16:56:06 +00:00
;; Linter Options
(let [fennel (require :lint.linters.fennel)]
(set fennel.globals [:vim]))
;; Configure Linters per FT
(set lint.linters_by_ft {:dockerfile [:hadolint]
:elixir [:credo]
2022-09-26 13:23:14 +00:00
;:fennel [:fennel]
:fish [:fish]
2022-06-18 23:39:25 +00:00
:markdown [:vale]
2022-04-19 16:07:34 +00:00
:nix [:deadnix :nix :statix]
2022-08-24 23:12:41 +00:00
:sh [:shellcheck]
:yaml [:yamllint]})
(fn setup-linting [opts]
(diagnostic.maybe-enable-diagnostics opts.buf)
2022-04-24 11:46:54 +00:00
(lint.try_lint)
(aucmd [:BufWinEnter :BufWritePost :InsertLeave]
{:callback #(lint.try_lint)
:buffer opts.buf
:group augroup
:desc "Run Linter"}))
(each [ft _ (pairs lint.linters_by_ft)]
(aucmd :FileType {:pattern ft
:callback setup-linting
:group augroup
:desc "Setup Linter"})))