mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-23 09:18:51 +02:00
fix(format): eslint should respect autoformat (#897)
This commit is contained in:
parent
0731f08ee4
commit
2ec4da7fa5
2 changed files with 9 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue