Hello everyone.
Unfortunately, I cannot quite figure out how to use eslint for formatting via lspconfig keymap, like for example: vim.keymap.set("n", "<Leader>F", function() vim.lsp.buf.format({ async = true }) end, opts)
I read and searched through quite some threads on GitHub, Reddit, and this Discourse, … and it seems that using eslint this way simply does not work; or is there any convenient way on how to make eslint format my file, i.e. fix eslint (format) errors via this keybinding?
NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Find my lspconfig.lua
file below:
return {
"neovim/nvim-lspconfig",
dependencies = {
{ "folke/neodev.nvim", config = true },
{ "williamboman/mason.nvim", config = true },
{ "williamboman/mason-lspconfig.nvim", config = true },
},
config = function()
-- local capabilities = vim.lsp.protocol.make_client_capabilities()
local on_attach = function(_, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
-- […]
vim.keymap.set("n", "<Leader>F", function() vim.lsp.buf.format({ async = true }) end, opts)
end
local servers = {
-- […]
eslint = {},
-- […]
stylelint_lsp = {
settings = {
stylelintplus = {
autoFixOnFormat = true,
},
},
},
sumneko_lua = {
settings = {
Lua = {
workspace = {
checkThirdParty = false,
},
telemetry = {
enable = false,
},
},
},
},
}
require("mason-lspconfig").setup({
ensure_installed = vim.tbl_keys(servers),
})
require("mason-lspconfig").setup_handlers({
function(server_name)
require("lspconfig")[server_name].setup({
-- capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name].settings,
})
end
})
end
}
Thank you very much.