From 79d80bd7dee5b60c4b4e5fb6e208bfcfaa447607 Mon Sep 17 00:00:00 2001 From: Pratik Tripathy Date: Wed, 10 Sep 2025 23:58:43 +0530 Subject: [PATCH] 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 --- common/.config/nvim/lsp/markdownlint.lua | 4 -- common/.config/nvim/lsp/prettier.lua | 13 ---- common/.config/nvim/lsp/shellcheck.lua | 4 -- common/.config/nvim/lsp/shellharden.lua | 4 -- common/.config/nvim/lsp/shfmt.lua | 4 -- common/.config/nvim/lua/core/lsp.lua | 6 +- .../.config/nvim/lua/plugins/formatting.lua | 63 +++++++------------ common/.config/nvim/lua/plugins/linting.lua | 15 ++--- scripts/package-list-brew | 2 - 9 files changed, 27 insertions(+), 88 deletions(-) delete mode 100644 common/.config/nvim/lsp/markdownlint.lua delete mode 100644 common/.config/nvim/lsp/prettier.lua delete mode 100644 common/.config/nvim/lsp/shellcheck.lua delete mode 100644 common/.config/nvim/lsp/shellharden.lua delete mode 100644 common/.config/nvim/lsp/shfmt.lua diff --git a/common/.config/nvim/lsp/markdownlint.lua b/common/.config/nvim/lsp/markdownlint.lua deleted file mode 100644 index d0d4107..0000000 --- a/common/.config/nvim/lsp/markdownlint.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - cmd = { "markdownlint-language-server", "--stdio" }, - filetypes = { "markdown" }, -} diff --git a/common/.config/nvim/lsp/prettier.lua b/common/.config/nvim/lsp/prettier.lua deleted file mode 100644 index fc55be1..0000000 --- a/common/.config/nvim/lsp/prettier.lua +++ /dev/null @@ -1,13 +0,0 @@ -return { - cmd = { "prettier", "--lsp" }, - filetypes = { - "javascript", - "typescript", - "css", - "scss", - "html", - "json", - "yaml", - }, - root_markers = { ".prettierrc", "package.json" }, -} diff --git a/common/.config/nvim/lsp/shellcheck.lua b/common/.config/nvim/lsp/shellcheck.lua deleted file mode 100644 index c8e2219..0000000 --- a/common/.config/nvim/lsp/shellcheck.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - cmd = { "shellcheck", "--format=json", "-" }, - filetypes = { "sh", "bash", "zsh" }, -} diff --git a/common/.config/nvim/lsp/shellharden.lua b/common/.config/nvim/lsp/shellharden.lua deleted file mode 100644 index 29f12fa..0000000 --- a/common/.config/nvim/lsp/shellharden.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - cmd = { "shellharden", "--suggest" }, - filetypes = { "sh", "bash", "zsh" }, -} diff --git a/common/.config/nvim/lsp/shfmt.lua b/common/.config/nvim/lsp/shfmt.lua deleted file mode 100644 index 43bd8e2..0000000 --- a/common/.config/nvim/lsp/shfmt.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - cmd = { "shfmt", "-l", "-" }, - filetypes = { "sh", "bash", "zsh" }, -} diff --git a/common/.config/nvim/lua/core/lsp.lua b/common/.config/nvim/lua/core/lsp.lua index ddde436..042c4e1 100644 --- a/common/.config/nvim/lua/core/lsp.lua +++ b/common/.config/nvim/lua/core/lsp.lua @@ -4,6 +4,7 @@ -- Step 2: Append the LSP server name in the below array ("newlsp") -- Step 3: Create file ("newlsp.lua") in ../../lsp/ -- Step 4: Return a lua table containing required lsp config in it +-- NOTE: Only LSPs here, NOT linters or formatter vim.lsp.enable({ "bashls", "cssls", @@ -12,13 +13,8 @@ vim.lsp.enable({ "html", "jsonls", "lua_ls", - "markdownlint", "marksman", - "prettier", "pylsp", - "shellcheck", - "shellharden", - "shfmt", "taplo", "trivy", "ts_ls", diff --git a/common/.config/nvim/lua/plugins/formatting.lua b/common/.config/nvim/lua/plugins/formatting.lua index 2c9b120..9a1af99 100644 --- a/common/.config/nvim/lua/plugins/formatting.lua +++ b/common/.config/nvim/lua/plugins/formatting.lua @@ -5,42 +5,33 @@ return { event = { "BufWritePre" }, opts = { formatters_by_ft = { - bash = { "shfmt", "shellharden", stop_after_first = true }, - css = { "prettierd", "prettier", stop_after_first = true }, - graphql = { "prettierd", "prettier", stop_after_first = true }, - html = { "prettierd", "prettier", stop_after_first = true }, - javascript = { "prettierd", "prettier", stop_after_first = true }, - javascriptreact = { "prettierd", "prettier", stop_after_first = true }, - json = { "prettierd", "prettier", stop_after_first = true }, + sh = { "shfmt" }, + bash = { "shfmt" }, + zsh = { "shfmt" }, + + graphql = { "prettierd" }, + css = { "prettierd" }, + html = { "prettierd" }, + javascript = { "prettierd" }, + javascriptreact = { "prettierd" }, + svelte = { "prettierd" }, + typescript = { "prettierd" }, + typescriptreact = { "prettierd" }, + json = { "prettierd" }, + lua = { "stylua" }, - markdown = { "markdownlint", "markdown-toc" }, + markdown = { "markdownlint" }, python = { "black" }, rust = { "rustfmt" }, - sh = { "shfmt", "shellharden", stop_after_first = true }, - 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 }, + yaml = { "yamlfmt" }, + ["_"] = { "trim_whitespace" }, }, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- 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, - lsp_format = lsp_format_opt, - } - end, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 500, + }, formatters = { injected = { options = { ignore_errors = true } }, shfmt = { prepend_args = { "-i", "4" } }, @@ -50,16 +41,6 @@ return { 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("") then - return true - end - end - end, - }, yamlfmt = { prepend_args = { "-formatter", diff --git a/common/.config/nvim/lua/plugins/linting.lua b/common/.config/nvim/lua/plugins/linting.lua index 1885cc8..f4f4efa 100644 --- a/common/.config/nvim/lua/plugins/linting.lua +++ b/common/.config/nvim/lua/plugins/linting.lua @@ -8,19 +8,12 @@ return { -- Linters are only required for dynamically typed languages lint.linters_by_ft = { - python = { "pylint", "codespell" }, - markdown = { "markdownlint", "codespell" }, + python = { "pylint" }, + markdown = { "markdownlint" }, yaml = { "yamllint" }, - lua = { "codespell" }, - bash = { "codespell" }, - sh = { "codespell" }, - zsh = { "codespell" }, - typescript = { "codespell" }, - javascript = { "codespell" }, - typescriptreact = { "codespell" }, - javascriptreact = { "codespell" }, dockerfile = { "hadolint" }, - html = { "codespell" }, + + ["*"] = { "codespell" }, } local markdownlint = lint.linters.markdownlint diff --git a/scripts/package-list-brew b/scripts/package-list-brew index f87b49b..729c703 100644 --- a/scripts/package-list-brew +++ b/scripts/package-list-brew @@ -17,13 +17,11 @@ markdownlint-cli marksman n neovim -prettier prettierd python-lsp-server python@3.12 rclone sccache -shellharden shodan speedtest-cli sqlite