diff --git a/lua/astrocommunity/pack/typescript/init.lua b/lua/astrocommunity/pack/typescript/init.lua index 03d9e73ec..385080791 100644 --- a/lua/astrocommunity/pack/typescript/init.lua +++ b/lua/astrocommunity/pack/typescript/init.lua @@ -49,7 +49,26 @@ return { }, { "williamboman/mason-lspconfig.nvim", - opts = function(_, opts) opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, "tsserver") end, + opts = function(_, opts) + opts.ensure_installed = utils.list_insert_unique(opts.ensure_installed, { "tsserver", "eslint" }) + + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("eslint_fix_creator", { clear = true }), + desc = "Create autocommand in buffers where eslint attaches", + callback = function(args) + if assert(vim.lsp.get_client_by_id(args.data.client_id)).name == "eslint" then + vim.api.nvim_create_autocmd("BufWritePost", { + desc = "Fix all eslint errors", + buffer = args.buf, + group = vim.api.nvim_create_augroup(("eslint_fix_%d"):format(args.buf), { clear = true }), + callback = function() + if vim.fn.exists ":EslintFixAll" > 0 then vim.cmd.EslintFixAll() end + end, + }) + end + end, + }) + end, }, { "jay-babu/mason-null-ls.nvim",