fix(neovim): LSP, Formatter, Linter all in their places

- Formatter: Don't need both prettier & prettierd. Only use prettierd
- Formatter: markdown-toc is LSP not formatter
- Formatter: shellharden isn't formatter
- Formatter: Only shfmt for shell formatting
- Formatter: Don't need prettier to format yaml
- Linter: codespell on all buffers
- Install script: Remove prettier & shellharden (its useless with bashls)
- LSP: markdownlint, prettier, shellcheck, shellharden, shfmt aren't LSP
This commit is contained in:
Pratik Tripathy
2025-09-10 23:58:43 +05:30
parent de0ae11f4a
commit 79d80bd7de
9 changed files with 27 additions and 88 deletions

View File

@@ -1,4 +0,0 @@
return {
cmd = { "markdownlint-language-server", "--stdio" },
filetypes = { "markdown" },
}

View File

@@ -1,13 +0,0 @@
return {
cmd = { "prettier", "--lsp" },
filetypes = {
"javascript",
"typescript",
"css",
"scss",
"html",
"json",
"yaml",
},
root_markers = { ".prettierrc", "package.json" },
}

View File

@@ -1,4 +0,0 @@
return {
cmd = { "shellcheck", "--format=json", "-" },
filetypes = { "sh", "bash", "zsh" },
}

View File

@@ -1,4 +0,0 @@
return {
cmd = { "shellharden", "--suggest" },
filetypes = { "sh", "bash", "zsh" },
}

View File

@@ -1,4 +0,0 @@
return {
cmd = { "shfmt", "-l", "-" },
filetypes = { "sh", "bash", "zsh" },
}

View File

@@ -4,6 +4,7 @@
-- Step 2: Append the LSP server name in the below array ("newlsp") -- Step 2: Append the LSP server name in the below array ("newlsp")
-- Step 3: Create file ("newlsp.lua") in ../../lsp/ -- Step 3: Create file ("newlsp.lua") in ../../lsp/
-- Step 4: Return a lua table containing required lsp config in it -- Step 4: Return a lua table containing required lsp config in it
-- NOTE: Only LSPs here, NOT linters or formatter
vim.lsp.enable({ vim.lsp.enable({
"bashls", "bashls",
"cssls", "cssls",
@@ -12,13 +13,8 @@ vim.lsp.enable({
"html", "html",
"jsonls", "jsonls",
"lua_ls", "lua_ls",
"markdownlint",
"marksman", "marksman",
"prettier",
"pylsp", "pylsp",
"shellcheck",
"shellharden",
"shfmt",
"taplo", "taplo",
"trivy", "trivy",
"ts_ls", "ts_ls",

View File

@@ -5,42 +5,33 @@ return {
event = { "BufWritePre" }, event = { "BufWritePre" },
opts = { opts = {
formatters_by_ft = { formatters_by_ft = {
bash = { "shfmt", "shellharden", stop_after_first = true }, sh = { "shfmt" },
css = { "prettierd", "prettier", stop_after_first = true }, bash = { "shfmt" },
graphql = { "prettierd", "prettier", stop_after_first = true }, zsh = { "shfmt" },
html = { "prettierd", "prettier", stop_after_first = true },
javascript = { "prettierd", "prettier", stop_after_first = true }, graphql = { "prettierd" },
javascriptreact = { "prettierd", "prettier", stop_after_first = true }, css = { "prettierd" },
json = { "prettierd", "prettier", stop_after_first = true }, html = { "prettierd" },
javascript = { "prettierd" },
javascriptreact = { "prettierd" },
svelte = { "prettierd" },
typescript = { "prettierd" },
typescriptreact = { "prettierd" },
json = { "prettierd" },
lua = { "stylua" }, lua = { "stylua" },
markdown = { "markdownlint", "markdown-toc" }, markdown = { "markdownlint" },
python = { "black" }, python = { "black" },
rust = { "rustfmt" }, rust = { "rustfmt" },
sh = { "shfmt", "shellharden", stop_after_first = true }, yaml = { "yamlfmt" },
svelte = { "prettierd", "prettier", stop_after_first = true },
typescript = { "prettierd", "prettier", stop_after_first = true },
typescriptreact = { "prettierd", "prettier", stop_after_first = true },
yaml = { "yamlfmt", "prettierd", stop_after_first = true },
zsh = { "shfmt", "shellharden", stop_after_first = true },
["_"] = { "trim_whitespace" }, ["_"] = { "trim_whitespace" },
}, },
format_on_save = function(bufnr) format_on_save = {
-- Disable "format_on_save lsp_fallback" for languages that don't lsp_fallback = true,
-- have a well standardized coding style. You can add additional async = false,
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true }
local lsp_format_opt
if disable_filetypes[vim.bo[bufnr].filetype] then
lsp_format_opt = "never"
else
lsp_format_opt = "fallback"
end
return {
quiet = false,
timeout_ms = 500, timeout_ms = 500,
lsp_format = lsp_format_opt, },
}
end,
formatters = { formatters = {
injected = { options = { ignore_errors = true } }, injected = { options = { ignore_errors = true } },
shfmt = { prepend_args = { "-i", "4" } }, shfmt = { prepend_args = { "-i", "4" } },
@@ -50,16 +41,6 @@ return {
vim.loop.os_homedir() .. "/.config/templates/markdownlint.json", vim.loop.os_homedir() .. "/.config/templates/markdownlint.json",
}, },
}, },
["markdown-toc"] = {
-- Format only if TOC present in the file
condition = function(_, ctx)
for _, line in ipairs(vim.api.nvim_buf_get_lines(ctx.buf, 0, -1, false)) do
if line:find("<!%-%- toc %-%->") then
return true
end
end
end,
},
yamlfmt = { yamlfmt = {
prepend_args = { prepend_args = {
"-formatter", "-formatter",

View File

@@ -8,19 +8,12 @@ return {
-- Linters are only required for dynamically typed languages -- Linters are only required for dynamically typed languages
lint.linters_by_ft = { lint.linters_by_ft = {
python = { "pylint", "codespell" }, python = { "pylint" },
markdown = { "markdownlint", "codespell" }, markdown = { "markdownlint" },
yaml = { "yamllint" }, yaml = { "yamllint" },
lua = { "codespell" },
bash = { "codespell" },
sh = { "codespell" },
zsh = { "codespell" },
typescript = { "codespell" },
javascript = { "codespell" },
typescriptreact = { "codespell" },
javascriptreact = { "codespell" },
dockerfile = { "hadolint" }, dockerfile = { "hadolint" },
html = { "codespell" },
["*"] = { "codespell" },
} }
local markdownlint = lint.linters.markdownlint local markdownlint = lint.linters.markdownlint

View File

@@ -17,13 +17,11 @@ markdownlint-cli
marksman marksman
n n
neovim neovim
prettier
prettierd prettierd
python-lsp-server python-lsp-server
python@3.12 python@3.12
rclone rclone
sccache sccache
shellharden
shodan shodan
speedtest-cli speedtest-cli
sqlite sqlite