dotfiles/config/common/nvim/lua/plugins/linters.lua

101 lines
2.8 KiB
Lua

return {
{
"williamboman/mason.nvim",
cmd = "Mason",
keys = { { "<leader>cm", "<cmd>Mason<cr>", desc = "Mason" } },
build = ":MasonUpdate",
opts = {
ensure_installed = {
"ansible-language-server",
"ansible-lint",
"lua-language-server",
"markdownlint-cli2",
"marksman",
"shfmt",
"stylua",
"terraform-ls",
"tflint",
"yaml-language-server",
"yamlfix",
"yamllint",
},
},
config = function(_, opts)
require("mason").setup(opts)
local mr = require("mason-registry")
local function ensure_installed()
for _, tool in ipairs(opts.ensure_installed) do
if mr.has_package(tool) then
local p = mr.get_package(tool)
if not p:is_installed() then
vim.notify("Mason: Installing " .. tool .. "...", vim.log.levels.INFO)
p:install():once("closed", function()
if p:is_installed() then
vim.notify("Mason: Successfully installed " .. tool, vim.log.levels.INFO)
else
vim.notify("Mason: Failed to install " .. tool, vim.log.levels.ERROR)
end
end)
end
else
vim.notify("Mason: Package '" .. tool .. "' not found", vim.log.levels.WARN)
end
end
end
if mr.refresh then
mr.refresh(ensure_installed)
else
ensure_installed()
end
end,
},
{
"mfussenegger/nvim-lint",
event = { "BufReadPre", "BufNewFile" },
config = function()
require("lint").linters_by_ft = {
markdown = { "markdownlint-cli2" },
terraform = { "terraform_validate" },
tf = { "terraform_validate" },
yaml = { "yamllint" },
}
local markdownlint = require("lint").linters["markdownlint-cli2"]
markdownlint.args = {
"--config",
vim.fn.stdpath("config") .. "/cfg_linters/global.markdownlint-cli2.yaml",
}
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
callback = function()
require("lint").try_lint()
end,
})
end,
},
{
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile" },
dependencies = { "mason.nvim" },
config = function()
require("conform").setup({
formatters_by_ft = {
["terraform-vars"] = { "terraform_fmt" },
bash = { "shfmt" },
lua = { "stylua" },
markdown = { "markdownlint-cli2" },
sh = { "shfmt" },
terraform = { "terraform_fmt" },
tf = { "terraform_fmt" },
zsh = { "shfmt" },
yaml = { "yamlfix" },
},
format_on_save = {
lsp_fallback = true,
async = false,
},
})
end,
},
}