kickstart.nvim/lua/rakshit/plugins/formatting.lua

61 lines
1.9 KiB
Lua
Raw Normal View History

2024-11-03 20:15:03 -08:00
return { -- Autoformat
2025-01-10 18:55:11 -08:00
"stevearc/conform.nvim",
event = { "BufWritePre", "BufReadPre", "BufNewFile" },
cmd = { "ConformInfo" },
2024-11-03 20:15:03 -08:00
keys = {
{
2025-01-10 18:55:11 -08:00
"<leader>f",
2024-11-03 20:15:03 -08:00
function()
2025-01-10 18:55:11 -08:00
require("conform").format({ async = true, lsp_format = "fallback" })
2024-11-03 20:15:03 -08:00
end,
2025-01-10 18:55:11 -08:00
mode = "",
desc = "[F]ormat buffer",
2024-11-03 20:15:03 -08:00
},
},
opts = {
notify_on_error = false,
2024-11-22 20:20:06 -08:00
notify_no_formatters = true,
2024-11-03 20:15:03 -08:00
format_on_save = {
lsp_fallback = true,
async = false,
2024-11-09 21:49:28 -08:00
timeout_ms = 5000,
2024-11-03 20:15:03 -08:00
},
formatters_by_ft = {
2025-01-10 18:55:11 -08:00
go = { "goimports", "gofmt" },
terraform = { "terraform_fmt" },
lua = { "stylua" },
javascript = { "prettier" },
typescript = { "prettier" },
javascriptreact = { "prettier" },
typescriptreact = { "prettier" },
svelte = { "prettier" },
css = { "prettier" },
html = { "prettier" },
json = { "prettier" },
yaml = { "prettier" },
markdown = { "prettier" },
graphql = { "prettier" },
liquid = { "prettier" },
2024-11-09 21:49:28 -08:00
-- python = { 'isort', 'black' },
-- You can use a function here to determine the formatters dynamically
python = function(bufnr)
2025-01-10 18:55:11 -08:00
if require("conform").get_formatter_info("ruff_format", bufnr).available then
return { "ruff_format" }
2024-11-09 21:49:28 -08:00
else
2025-01-10 18:55:11 -08:00
return { "isort", "black" }
2024-11-09 21:49:28 -08:00
end
end,
-- Use the "*" filetype to run formatters on all filetypes.
2025-01-10 18:55:11 -08:00
["*"] = { "codespell" },
2024-11-09 21:49:28 -08:00
-- Use the "_" filetype to run formatters on filetypes that don't
-- have other formatters configured.
2025-01-10 18:55:11 -08:00
["_"] = { "trim_whitespace" },
2024-11-03 20:15:03 -08:00
-- Conform can also run multiple formatters sequentially
-- python = { "isort", "black" },
--
-- You can use 'stop_after_first' to run the first available formatter from the list
-- javascript = { "prettierd", "prettier", stop_after_first = true },
},
},
}