nvim mhartington/formatter.nvim -> stevearc/conform.nvim

This commit is contained in:
Henrik Bakken
2025-03-26 12:15:18 +01:00
parent 1768faf984
commit 2da877e76f
+37 -69
View File
@@ -1139,79 +1139,47 @@ local function makespec_lint()
end end
local function makespec_autoformat() local function makespec_autoformat()
local function ruff_fix()
return { exe = "ruff", args = { "check", "--select I,F,UP", "--fix-only", "-" }, stdin = true }
end
local function ruff_format() return { exe = "ruff", args = { "format", "-" }, stdin = true } end
local function stylua_format()
local util = require("formatter.util")
return {
exe = "stylua",
args = {
"--search-parent-directories",
"--indent-type Spaces",
"--collapse-simple-statement Always",
"--stdin-filepath",
util.escape_path(util.get_current_buffer_file_path()),
"--",
"-",
},
stdin = true,
}
end
local function yaml_format()
return {
exe = "yamlfmt",
args = {
"-formatter indentless_arrays=true,retain_line_breaks=true,line_ending=lf,max_line_length=100,pad_line_comments=2",
"-in",
},
stdin = true,
}
end
local function typescript_format()
local util = require("formatter.util")
return {
exe = "eslint_d",
args = {
"--stdin",
"--debug",
"--stdin-filename",
util.escape_path(util.get_current_buffer_file_path()),
"--fix-to-stdout",
},
stdin = true,
try_node_modules = true,
ignore_exitcode = true,
}
end
return { return {
"mhartington/formatter.nvim", -- TODO move to conform "stevearc/conform.nvim",
lazy = true,
cmd = { "ConformInfo" },
keys = { keys = {
{ "<leader>f", "<cmd>Format<cr>", silent = true, noremap = true }, { "<leader>f", function() require("conform").format() end, silent = true, noremap = true },
{ "<leader>F", "<cmd>FormatWrite<cr>", silent = true, noremap = true }, { "<leader>lf", "<cmd>e ~/.local/state/nvim/conform.log<cr>", noremap = true },
}, },
config = function() opts = {
require("formatter").setup({ formatters_by_ft = {
logging = true, ["_"] = { "trim_whitespace" },
log_level = vim.log.levels.DEBUG, css = { "prettierd", "prettier", stop_after_first = true },
filetype = { go = { "gofumpt", "golines" },
python = { ruff_fix, ruff_format }, html = { "prettierd", "prettier", stop_after_first = true },
lua = { stylua_format }, javascript = { "prettierd", "prettier", stop_after_first = true },
yaml = { yaml_format }, json = { "jq" },
typst = { function() return { exe = "typstyle", stdin = true } end }, lua = { "stylua" },
typescript = { typescript_format }, markdown = { "prettierd", "prettier", stop_after_first = true },
go = { require("formatter.filetypes.go").gofumpt, require("formatter.filetypes.go").golines }, python = { "ruff_format", "ruff_fix", "ruff_organize_imports" },
sh = { require("formatter.filetypes.sh").shfmt }, sh = { "shfmt" },
javascript = { require("formatter.filetypes.javascript").prettierd }, bash = { "shfmt" },
html = { require("formatter.filetypes.html").prettierd }, typescript = { "eslint_d" },
css = { require("formatter.filetypes.css").prettierd }, typst = { "typstyle" },
markdown = { require("formatter.filetypes.markdown").prettierd }, yaml = { "yamlfix", "yamlfmt" },
json = { require("formatter.filetypes.json").jq }, },
["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace }, default_format_opts = {
timeout_ms = 3000,
lsp_format = "fallback",
},
formatters = {
javascript = { require_cwd = true },
stylua = { append_args = { "--indent-type", "Spaces", "--collapse-simple-statement", "Always" } },
ruff_fix = { append_args = { "--select", "I,F,UP" } },
yamlfmt = {
append_args = {
"-formatter",
"indentless_arrays=true,retain_line_breaks=true,line_ending=lf,max_line_length=100,pad_line_comments=2",
},
}, },
}) },
end, },
} }
end end