Skip to content

Commit

Permalink
perf(eslint): only run EslintFixAll for the current buffer when there…
Browse files Browse the repository at this point in the history
… are diagnostics from eslint
  • Loading branch information
folke committed May 19, 2023
1 parent b4099a6 commit b227d97
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lua/lazyvim/plugins/extras/linting/eslint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ return {
"neovim/nvim-lspconfig",
-- other settings removed for brevity
opts = {
---@type lspconfig.options
servers = {
eslint = {
settings = {
Expand All @@ -15,8 +16,12 @@ return {
eslint = function()
vim.api.nvim_create_autocmd("BufWritePre", {
callback = function(event)
if require("lspconfig.util").get_active_client_by_name(event.buf, "eslint") then
vim.cmd("EslintFixAll")
local client = vim.lsp.get_active_clients({ bufnr = event.buf, name = "eslint" })[1]
if client then
local diag = vim.diagnostic.get(event.buf, { namespace = vim.lsp.diagnostic.get_namespace(client.id) })
if #diag > 0 then
vim.cmd("EslintFixAll")
end
end
end,
})
Expand Down

0 comments on commit b227d97

Please sign in to comment.