diff options
Diffstat (limited to 'store/config/nvim/lua/setup/plugins')
-rw-r--r-- | store/config/nvim/lua/setup/plugins/conform.lua | 18 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/plugins/init.lua | 1 | ||||
-rw-r--r-- | store/config/nvim/lua/setup/plugins/lint.lua | 80 |
3 files changed, 38 insertions, 61 deletions
diff --git a/store/config/nvim/lua/setup/plugins/conform.lua b/store/config/nvim/lua/setup/plugins/conform.lua deleted file mode 100644 index e14c3f9..0000000 --- a/store/config/nvim/lua/setup/plugins/conform.lua +++ /dev/null @@ -1,18 +0,0 @@ -local function setup() - require("conform").setup({ - formatters_by_ft = { - javascript = { "prettierd", "prettier", stop_after_first = true }, - typescript = { "prettierd", "prettier", stop_after_first = true }, - javascriptreact = { "prettierd", "prettier", stop_after_first = true }, - typescriptreact = { "prettierd", "prettier", stop_after_first = true }, - markdown = { "prettierd", "prettier", stop_after_first = true }, - }, - default_format_opts = { - lsp_format = "fallback", - }, - }) -end - -return { - setup = setup -} diff --git a/store/config/nvim/lua/setup/plugins/init.lua b/store/config/nvim/lua/setup/plugins/init.lua index 88eca4f..8f1346b 100644 --- a/store/config/nvim/lua/setup/plugins/init.lua +++ b/store/config/nvim/lua/setup/plugins/init.lua @@ -15,7 +15,6 @@ local function setup() require("setup.plugins.tree-sitter").setup() require("setup.plugins.lint").setup() - require("setup.plugins.conform").setup() require("setup.plugins.cmp").setup() require("nvim-autopairs").setup {} end diff --git a/store/config/nvim/lua/setup/plugins/lint.lua b/store/config/nvim/lua/setup/plugins/lint.lua index 928841d..d03f539 100644 --- a/store/config/nvim/lua/setup/plugins/lint.lua +++ b/store/config/nvim/lua/setup/plugins/lint.lua @@ -1,4 +1,6 @@ -local lint = require("lint") +--- spellchecker: ignore markdownlintrc + +---@alias CruLinter { name: string, config_patterns: string[], filetypes: string[] | nil, fast: boolean } local cspell = { name = "cspell", @@ -31,15 +33,30 @@ local markdownlint = { fast = true, } -local linters = { cspell, markdownlint } - -local linter_names = vim.tbl_map(function(l) return l.name end, linters) +local linters = { cspell = cspell, markdownlint = markdownlint } -local function cru_lint(linter, opt) - opt = opt or {} +---@param linter CruLinter +---@param buf integer +---@return string | nil +local function find_config(linter, buf) + local files = vim.fs.find(linter.config_patterns, { + path = vim.api.nvim_buf_get_name(buf), upward = true }) + if #files ~= 0 then + return files[1]; + end + return nil +end - local buf = opt.buf or 0 +vim.list_extend(require("lint.linters.markdownlint").args, { + "--config", + function() + return find_config(markdownlint, 0); + end +}) +---@param linter CruLinter +---@param buf integer +function vim.crupest.lint(linter, buf) if linter.filetypes then local filetype = vim.api.nvim_get_option_value("filetype", { buf = buf }) if not vim.list_contains(linter.filetypes, filetype) then @@ -47,50 +64,29 @@ local function cru_lint(linter, opt) end end - if 0 ~= #vim.fs.find(linter.config_patterns, { - path = vim.api.nvim_buf_get_name(opt.buf), upward = true }) then - lint.try_lint(linter.name) + if find_config(linter, buf) then + require("lint").try_lint(linter.name) end end -local function cru_lint_one(name, opt) - for _, linter in ipairs(linters) do - if linter.name == name then - cru_lint(linter, opt) - return - end - end - vim.notify("No linter named " .. name .. " is configured.", vim.log.levels.ERROR, {}) -end - -local function cru_lint_all(opt, fast) - for _, linter in ipairs(linters) do +function vim.crupest.lint_all(buf, fast) + for _, linter in pairs(linters) do if not fast or linter.fast then - cru_lint(linter, opt) + vim.crupest.lint(linter, buf) end end end -local function cru_lint_all_fast(opt) - local buf = opt.buf - if vim.api.nvim_get_option_value("buftype", { buf = buf }) == "" then - cru_lint_all(opt, true) - end -end - local function setup() - vim.api.nvim_create_autocmd({ "BufReadPost", "InsertLeave", "TextChanged" }, { callback = cru_lint_all_fast }) - - local function cru_lint_cmd(opt) - if #opt.args == 0 then - cru_lint_all(opt, false) - else - cru_lint_one(opt.args, opt) - end - end - - vim.api.nvim_create_user_command("CruLint", cru_lint_cmd, - { nargs = '?', complete = function() return linter_names end }) + vim.api.nvim_create_autocmd( + { "BufReadPost", "InsertLeave", "TextChanged" }, + { + callback = function(opt) + if vim.api.nvim_get_option_value("buftype", { buf = opt.buf }) == "" then + vim.crupest.lint_all(opt.buf, true) + end + end + }) end return { |