feat(format): add biome formatter and remove javascript/typescript formatters

This commit is contained in:
sankalp committed 2025-09-19 20:57:52 +05:45
1 parent 8a703c0a2f
commit 2be869ba5b
1 file changed
+64 -63
+64 -63
View File
@@ -1,66 +1,67 @@
return { return {
"stevearc/conform.nvim", 'stevearc/conform.nvim',
dependencies = { "zapling/mason-conform.nvim" }, dependencies = { 'zapling/mason-conform.nvim' },
event = "BufWritePre", event = 'BufWritePre',
cmd = "ConformInfo", cmd = 'ConformInfo',
keys = { "<leader>tf" }, keys = { '<leader>tf' },
config = function() config = function()
require("conform").setup({ require('conform').setup({
formatters = { formatters = {
["markdown-toc"] = { ['markdown-toc'] = {
condition = function(_, ctx) condition = function(_, ctx)
for _, line in ipairs(vim.api.nvim_buf_get_lines(ctx.buf, 0, -1, false)) do for _, line in ipairs(vim.api.nvim_buf_get_lines(ctx.buf, 0, -1, false)) do
if line:find("<!%-%-% toc %-%->") then if line:find('<!%-%-% toc %-%->') then
return true return true
end end
end end
end, end,
}, },
["markdownlint-cli2"] = { ['markdownlint-cli2'] = {
condition = function(_, ctx) condition = function(_, ctx)
local diag = vim.tbl_filter(function(d) local diag = vim.tbl_filter(function(d)
return d.source == "markdownlint" return d.source == 'markdownlint'
end, vim.diagnostic.get(ctx.buf)) end, vim.diagnostic.get(ctx.buf))
return #diag > 0 return #diag > 0
end, end,
}, },
}, },
formatters_by_ft = { formatters_by_ft = {
["lua"] = { "stylua" }, ['lua'] = { 'stylua' },
["python"] = { "ruff_fix", "ruff_format", "ruff_organize_imports" }, ['python'] = { 'ruff_fix', 'ruff_format', 'ruff_organize_imports' },
["javascript"] = { "prettier" }, ['javascript'] = { 'biome' },
["typescript"] = { "prettier" }, ['typescript'] = { 'biome' },
["markdown"] = { "prettier", "markdownlint-cli2", "markdown-toc" }, ['markdown'] = { 'prettier', 'markdownlint-cli2', 'markdown-toc' },
["markdown.mdx"] = { "prettier", "markdownlint-cli2", "markdown-toc" }, ['markdown.mdx'] = { 'prettier', 'markdownlint-cli2', 'markdown-toc' },
["mdx"] = { "prettier" }, ['mdx'] = { 'prettier' },
["_"] = { "trim_whitespace" }, ['_'] = { 'trim_whitespace' },
}, },
options = { options = {
stop_after_first = true, stop_after_first = true,
}, },
format_after_save = function(bufnr) format_after_save = function(bufnr)
if not vim.b[bufnr].conform_disable then if not vim.b[bufnr].conform_disable then
return { return {
lsp_format = "fallback", lsp_format = 'fallback',
} }
end end
end, end,
}) })
vim.keymap.set("n", "<leader>tf", function() vim.keymap.set('n', '<leader>tf', function()
vim.b.conform_disable = not vim.b.conform_disable vim.b.conform_disable = not vim.b.conform_disable
local status = vim.b.conform_disable and "disabled" or "enabled" local status = vim.b.conform_disable and 'disabled' or 'enabled'
vim.notify("Autoformat " .. status, vim.log.levels.INFO) vim.notify('Autoformat ' .. status, vim.log.levels.INFO)
end) end)
require("mason-conform").setup({ require('mason-conform').setup({
ensure_installed = { ensure_installed = {
"ruff", 'ruff',
"stylua", 'stylua',
"prettier", 'prettier',
"markdown-toc", 'markdown-toc',
"markdownlint-cli2", 'markdownlint-cli2',
}, 'biome',
automatic_installation = true, },
}) automatic_installation = true,
end, })
end,
} }