feat(nvim): add formatting

This commit is contained in:
Stefan Imhoff
2024-02-27 19:16:46 +01:00
parent e5e04c96df
commit 2a8b6d9ecb
2 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
-- Lightweight yet powerful formatter plugin for Neovim
-- https://github.com/stevearc/conform.nvim
return {
"stevearc/conform.nvim",
event = { "BufWritePre", "BufNewFile" },
keys = {
{
"<leader>mp",
mode = { "n", "v" },
function()
require("conform").format({
lsp_fallback = true,
async = false,
timeout_ms = 500,
})
end,
desc = "Format file or range (in visual mode)",
},
},
opts = {
formatters = {
eslint_d = {
command = "eslint_d",
args = { "--fix-to-stdout", "--stdin", "--stdin-filename", "$FILENAME" },
stdin = true,
},
},
formatters_by_ft = {
astro = { "prettier" },
css = { "prettier" },
graphql = { "prettier" },
html = { "prettier" },
javascript = { "prettier", "eslint_d" },
javascriptreact = { "prettier", "eslint_d" },
json = { "prettier" },
lua = { "stylua" },
markdown = { "prettier" },
svelte = { "prettier" },
typescript = { "prettier", "eslint_d" },
typescriptreact = { "prettier", "eslint_d" },
yaml = { "prettier" },
python = { "isort", "black" },
},
},
}

View File

@@ -5,6 +5,7 @@ return {
opts = {
ensure_installed = {
"astro-language-server",
"black",
"cspell",
"css-lsp",
"cssmodules-language-server",
@@ -13,6 +14,7 @@ return {
"eslint-lsp",
"eslint_d",
"html-lsp",
"isort",
"json-lsp",
"lua-language-server",
"prettier",