init.lua/after/plugin/code-tools.lua

58 lines
1.2 KiB
Lua
Raw Normal View History

-- [[ Formatters Setup ]]
local conform = require("conform")
conform.setup({
formatters_by_ft = {
python = { "isort", "black" },
lua = { "stylua" },
sh = { "shfmt" },
bash = { "shfmt" },
},
})
-- only format with keybinding, don't like code chaning everytime I save
2023-12-26 21:27:59 +01:00
vim.keymap.set({ "n", "v" }, "<leader>vf", function()
conform.format({
lsp_fallback = true,
})
end, { desc = "Format file or range (in visual mode)" })
-- [[ Linter's Setup ]]
local lint = require("lint")
-- fix mypy import's error
lint.linters.mypy.args = {
function()
local virtual = os.getenv("VIRTUAL_ENV") or os.getenv("CONDA_PREFIX") or "/usr"
return "--python-executable", virtual .. "/bin/python3"
end,
}
lint.linters_by_ft = {
python = { "mypy", "ruff" },
}
-- setup auto linting
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,
})
-- [[ Mason Tools Installer ]]
local mason_tool_installer = require("mason-tool-installer")
mason_tool_installer.setup({
ensure_installed = {
"isort",
"black",
"stylua",
"shfmt",
"mypy",
"ruff",
},
})