From 4a7e003ea1baecfd428798e16a4caa1aa08f24e3 Mon Sep 17 00:00:00 2001 From: Felix Nehrke Date: Fri, 27 Mar 2026 00:52:12 +0100 Subject: [PATCH] Fix formatting via eslint on save in neovim When I saved files in my eslint-formatted projects I was wondering about slight differences between the results of running `eslint --fix` vs. the autoamtic formatting when I save a file in neovim. As it turned out I ran the wrong command indeed. This changes fixes that by simply calling the correct command on save. Note that this looks "bigger" but it's actually a copy of the built-in `LspEslintFixAll` of neovim. Reference: https://github.com/neovim/nvim-lspconfig/blob/1a6d69206749a646ef28bfb39460610b14baff40/doc/configs.md#eslint Reference: https://github.com/neovim/nvim-lspconfig/blob/89fd0361b33d5bf452c345e89ea7099ac88ab607/lsp/eslint.lua#L92-L104 --- .config/nvim/lua/plugins/lsp.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index b91d49d..63a872b 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -77,9 +77,15 @@ return { group = augroup, buffer = bufnr, callback = function() - if vim.bo.filetype == "typescript" then - vim.lsp.buf.format() - end + client:request_sync("workspace/executeCommand", { + command = "eslint.applyAllFixes", + arguments = { + { + uri = vim.uri_from_bufnr(bufnr), + version = vim.lsp.util.buf_versions[bufnr], + } + } + }) end, }) end,