2022-04-19 12:56:22 +00:00
|
|
|
(let [lint (require :lint)
|
2022-04-27 20:17:59 +00:00
|
|
|
diagnostic (require :nifoc.diagnostic)
|
2022-04-19 12:56:22 +00:00
|
|
|
augroup (vim.api.nvim_create_augroup :NifocLint {:clear true})
|
2022-11-27 16:12:49 +00:00
|
|
|
aucmd vim.api.nvim_create_autocmd
|
|
|
|
project-root (vim.fs.dirname (. (vim.fs.find [:.git] {:upward true}) 1))]
|
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 "") {}
|
2023-01-24 13:33:54 +00:00
|
|
|
(let [findings (vim.json.decode output)
|
|
|
|
filtered-findings (vim.tbl_filter #(not= $1.line
|
|
|
|
nil)
|
|
|
|
findings.results)]
|
2022-04-19 16:07:34 +00:00
|
|
|
(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})
|
2023-01-24 13:33:54 +00:00
|
|
|
filtered-findings))))})
|
2022-04-21 16:56:06 +00:00
|
|
|
;; Linter Options
|
2022-11-27 16:12:49 +00:00
|
|
|
(let [checkstyle (require :lint.linters.checkstyle)
|
|
|
|
fennel (require :lint.linters.fennel)]
|
|
|
|
(when (not= project-root nil)
|
|
|
|
(set checkstyle.config_file
|
|
|
|
(.. project-root :/config/checkstyle/checkstyle.xml)))
|
2022-12-19 21:02:48 +00:00
|
|
|
(set fennel.globals [:vim :wezterm]))
|
2022-04-21 16:56:06 +00:00
|
|
|
;; Configure Linters per FT
|
2022-04-19 12:56:22 +00:00
|
|
|
(set lint.linters_by_ft {:dockerfile [:hadolint]
|
|
|
|
:elixir [:credo]
|
2023-03-27 19:19:01 +00:00
|
|
|
:fennel [:fennel]
|
2022-04-27 20:17:59 +00:00
|
|
|
:fish [:fish]
|
2022-11-27 16:12:49 +00:00
|
|
|
:java [:checkstyle]
|
2022-04-19 16:07:34 +00:00
|
|
|
:nix [:deadnix :nix :statix]
|
2023-07-19 12:48:38 +00:00
|
|
|
:sh [:shellcheck]})
|
2022-04-19 12:56:22 +00:00
|
|
|
|
|
|
|
(fn setup-linting [opts]
|
2022-04-27 20:17:59 +00:00
|
|
|
(diagnostic.maybe-enable-diagnostics opts.buf)
|
2022-04-24 11:46:54 +00:00
|
|
|
(lint.try_lint)
|
2022-04-24 18:10:14 +00:00
|
|
|
(aucmd [:BufWinEnter :BufWritePost :InsertLeave]
|
2022-04-27 20:17:59 +00:00
|
|
|
{:callback #(lint.try_lint)
|
|
|
|
:buffer opts.buf
|
|
|
|
:group augroup
|
|
|
|
:desc "Run Linter"}))
|
2022-04-19 12:56:22 +00:00
|
|
|
|
|
|
|
(each [ft _ (pairs lint.linters_by_ft)]
|
2022-04-27 20:17:59 +00:00
|
|
|
(aucmd :FileType {:pattern ft
|
|
|
|
:callback setup-linting
|
|
|
|
:group augroup
|
|
|
|
:desc "Setup Linter"})))
|