refactor(nvim): replace formatter & nvim-lint with none-ls
All checks were successful
Check Formatting of Files / Check-Formatting (push) Successful in 44s

This commit is contained in:
Price Hiller 2024-03-20 08:51:43 -05:00
parent 5257f4b46a
commit 9421365706
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
3 changed files with 32 additions and 96 deletions

View File

@ -1,79 +0,0 @@
return {
{
"mhartington/formatter.nvim",
keys = {
{
"<leader>lf",
function()
local active_clients = vim.iter(
vim.lsp.get_clients({ bufnr = 0, method = "textDocument/formatting" })
)
:filter(function(lsp_client)
-- Exclude some language server formatters.
--
-- I chose not to override the `textDocument/formatting` handler because
-- it felt kinda hacky and some language servers don't play nice with
-- changing their handlers. Figured this was easier.
if lsp_client.config and lsp_client.config.name then
return not vim.list_contains({
"lua_ls",
}, lsp_client.config.name)
end
return true
end)
if #active_clients > 0 then
vim.lsp.buf.format({ async = true })
else
vim.cmd.Format()
end
end,
-- I know this is a lie below, but I'm used to the key being LSP bound, so fuck it
desc = "LSP: Format",
mode = { "v", "n" },
},
},
opts = function()
local filetypes = require("formatter.filetypes")
return {
logging = true,
log_level = vim.log.levels.WARN,
filetype = {
markdown = filetypes.markdown.prettierd,
css = filetypes.css.prettierd,
lua = filetypes.lua.stylua,
sql = function()
return {
exe = "sql-formatter",
args = {
"-l",
"postgresql",
"--fix",
},
}
end,
zsh = function()
return {
exe = "shfmt",
args = {
"-",
},
stdin = true,
}
end,
asm = function()
return {
exe = "asmfmt",
stdin = true,
}
end,
typst = function()
return {
exe = "typstfmt",
stdin = true,
}
end,
},
}
end,
},
}

View File

@ -192,9 +192,41 @@ return {
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
config = true, config = true,
}, },
{
"nvimtools/none-ls.nvim",
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.asmfmt,
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.typstfmt,
null_ls.builtins.formatting.cmake_format,
null_ls.builtins.formatting.shfmt,
null_ls.builtins.formatting.shellharden,
null_ls.builtins.formatting.prettierd,
null_ls.builtins.diagnostics.hadolint,
},
})
end,
},
}, },
keys = { keys = {
{ "<leader>l", desc = "> LSP" }, { "<leader>l", desc = "> LSP" },
{
"<leader>lf",
function()
vim.lsp.buf.format({
async = true,
filter = function(client)
return not vim.list_contains({ "lua_ls" }, client.name)
end,
})
end,
desc = "LSP: Format",
mode = { "v", "n" },
},
{ {
"<leader>lh", "<leader>lh",
function() function()

View File

@ -1,17 +0,0 @@
return {
{
"mfussenegger/nvim-lint",
event = { "BufReadPre", "BufNewFile" },
config = function()
require("lint").linters_by_ft = {
markdown = { "proselint" },
dockerfile = { "hadolint" },
}
vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter" }, {
callback = function()
require("lint").try_lint()
end,
})
end,
},
}