diff options
Diffstat (limited to 'nvim')
-rw-r--r-- | nvim/.config/nvim/lua/plugins/lint.lua | 76 |
1 files changed, 22 insertions, 54 deletions
diff --git a/nvim/.config/nvim/lua/plugins/lint.lua b/nvim/.config/nvim/lua/plugins/lint.lua index bbbac96..443971e 100644 --- a/nvim/.config/nvim/lua/plugins/lint.lua +++ b/nvim/.config/nvim/lua/plugins/lint.lua @@ -1,31 +1,3 @@ -local function try_lint() - local lint = require("lint") - local names = lint._resolve_linter_by_ft(vim.bo.filetype) - - names = vim.list_extend({}, names) - - if #names == 0 then - vim.list_extend(names, lint.linters_by_ft["_"] or {}) - end - - vim.list_extend(names, lint.linters_by_ft["*"] or {}) - - names = vim.iter(names) - :filter(function(name) - local linter = lint.linters[name] - if type(linter) == "function" then - linter = linter() - end - ---@diagnostic disable-next-line: undefined-field - return linter.condition == nil or linter.condition() - end) - :totable() - - if #names > 0 then - lint.try_lint(names) - end -end - ---@type LazyPluginSpec local M = { "mfussenegger/nvim-lint", @@ -36,43 +8,39 @@ local M = { zsh = { "zsh" }, systemd = { "systemdlint" }, }, - linters = { - selene = { - prepend_args = { - function() - return string.format( - "--config=%s", - vim.fs.joinpath(vim.fs.root(0, "selene.toml"), "selene.toml") - ) - end, - }, - condition = function() - return vim.fs.root(0, "selene.toml") - end, - }, - }, }, } function M:init() - vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave" }, { - group = vim.api.nvim_create_augroup("nvim-lint", { clear = true }), - callback = U.debounce(100, try_lint), + local augroup = vim.api.nvim_create_augroup("user.lint", { clear = true }) + vim.api.nvim_create_autocmd("FileType", { + group = augroup, + pattern = vim.tbl_keys(self.opts.linters_by_ft), + callback = function(args) + vim.api.nvim_clear_autocmds({ buffer = args.buf, group = augroup }) + local debounced_lint = U.debounce(100, require("lint").try_lint) + debounced_lint() + vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave" }, { + group = augroup, + buffer = args.buf, + callback = function() + debounced_lint() + end, + desc = "lint", + }) + end, + desc = "setup nvim-lint", }) end function M:config(opts) local lint = require("lint") lint.linters_by_ft = opts.linters_by_ft - vim.iter(opts.linters):each(function(name, linter) - if type(linter) == "table" and type(lint.linters[name]) == "table" then - linter = vim.tbl_deep_extend("keep", linter, require("lint").linters[name] or {}) - linter.args = vim.iter({ linter.prepend_args }):flatten():rev():fold(linter.args or {}, function(args, arg) - table.insert(args, 1, arg) - return args - end) + table.insert(lint.linters.selene.args, function() + local root = vim.fs.root(0, "selene.toml") + if root then + return string.format("--config=%s", vim.fs.joinpath(root, "selene.toml")) end - lint.linters[name] = linter end) end |