fix(format): eslint should respect autoformat (#897)
This commit is contained in:
@ -16,6 +16,11 @@ return {
|
|||||||
eslint = function()
|
eslint = function()
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
callback = function(event)
|
callback = function(event)
|
||||||
|
if not require("lazyvim.plugins.lsp.format").enabled() then
|
||||||
|
-- exit early if autoformat is not enabled
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local client = vim.lsp.get_active_clients({ bufnr = event.buf, name = "eslint" })[1]
|
local client = vim.lsp.get_active_clients({ bufnr = event.buf, name = "eslint" })[1]
|
||||||
if client then
|
if client then
|
||||||
local diag = vim.diagnostic.get(event.buf, { namespace = vim.lsp.diagnostic.get_namespace(client.id) })
|
local diag = vim.diagnostic.get(event.buf, { namespace = vim.lsp.diagnostic.get_namespace(client.id) })
|
||||||
|
@ -5,6 +5,10 @@ local M = {}
|
|||||||
---@type PluginLspOpts
|
---@type PluginLspOpts
|
||||||
M.opts = nil
|
M.opts = nil
|
||||||
|
|
||||||
|
function M.enabled()
|
||||||
|
return M.opts.autoformat
|
||||||
|
end
|
||||||
|
|
||||||
function M.toggle()
|
function M.toggle()
|
||||||
if vim.b.autoformat == false then
|
if vim.b.autoformat == false then
|
||||||
vim.b.autoformat = nil
|
vim.b.autoformat = nil
|
||||||
|
Reference in New Issue
Block a user