LazyVim / LazyVim

Neovim config for the lazy
https://lazyvim.github.io/
Apache License 2.0
16.79k stars 1.18k forks source link

bug: (javascript/typescript) auto format does not use my .eslintrc #380

Closed fegyi001 closed 1 year ago

fegyi001 commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.9.0-dev-1001+gcbd4480f9

Operating system/version

MacOS 13.2.1

Describe the bug

(Foreword: I'm quite beginner with neovim/lazyvim etc, just switched to lazyvim from nvchad.)

While eslint errors are shown correctly, on save lazyvim does not seem to use eslint rules (e.g. delete extra lines, remove whitespaces when needed etc). So my file is fine, no eslint errors, hit save, and reformatted somehow, and now shows eslint errors.

An example: this is a file BEFORE saving:

image

And when I save this is how it looks like after auto formatting:

image

It has a prettier-related problem which is fine, I have prettier rules in my .eslintrc conf file. lazyvim recognizes the problem just fine:

image

How could I tell lazyvim to use my eslintrc config file when saving a typescript/javascript file?

Steps To Reproduce

  1. Edit file, make sure no eslint errors are present
  2. Save file
  3. On save, lazyvim reformats file, but does not use my .eslintrc file

Expected Behavior

lazyvim should be able to use existing eslint config files when possible.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/LazyVim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
folke commented 1 year ago

Add the following:

       {
    "neovim/nvim-lspconfig",
    opts = {
      servers = { eslint = {} },
      setup = {
        eslint = function()
          require("lazyvim.util").on_attach(function(client)
            if client.name == "eslint" then
              client.server_capabilities.documentFormattingProvider = true
            elseif client.name == "tsserver" then
              client.server_capabilities.documentFormattingProvider = false
            end
          end)
        end,
      },
    },
  },
madtrick commented 8 months ago

Hi @folke, is this still the way to disable the formatting done by tsserver?

I digged through the issues/commits and found that in response to this other issue https://github.com/LazyVim/LazyVim/issues/249#issuecomment-1426998926 you pushed some changes to disable formatting if the client had it disable.

That code is gone since https://github.com/LazyVim/LazyVim/commit/f1a8f24a361d0de198f6b1458168652a6835c932 (or even earlier) so I'm wondering if now we should be using another way to fix this interference between the two format attempts.