mantoni / eslint_d.js

Speed up eslint to accelerate your development workflow
MIT License
1.1k stars 69 forks source link

[nvim none-ls] No ESLint configuration found #311

Open piersolenski opened 1 month ago

piersolenski commented 1 month ago

I've recently switched a project to the new eslint.config.js format. When using eslint, it works perfectly (albeit slow!), when I switch to eslint_d I get the following error:

Error: No ESLint configuration found in /Users/...

I am using the following version

eslint_d: v14.0.3, bundled eslint: v9.8.0

The tickets below suggest that it should be working with this version:

I'm using eslint_d with Neovim and https://github.com/nvimtools/none-ls.nvim. My config looks like this:

-- Diagnostics, code actions, formatting, etc
return {
    "nvimtools/none-ls.nvim",
    lazy = false,
    dependencies = {
        "gbprod/none-ls-shellcheck.nvim",
        "jay-babu/mason-null-ls.nvim",
        "nvimtools/none-ls-extras.nvim",
        "williamboman/mason.nvim",
    },
    config = function()
        local null_ls = require("null-ls")
        local mason_null_ls = require("mason-null-ls")

        local formatting = null_ls.builtins.formatting
        local diagnostics = null_ls.builtins.diagnostics

        -- Helper to conditionally register eslint handlers only if eslint is
        -- config. If eslint is not configured for a project, it just fails.
        local function has_eslint_config(utils)
            return utils.root_has_file({
                ".eslintrc",
                ".eslintrc.cjs",
                ".eslintrc.js",
                ".eslintrc.json",
                "eslint.config.cjs",
                "eslint.config.js",
                "eslint.config.mjs",
            })
        end

        null_ls.setup({
            sources = {
                diagnostics.pylint,
                diagnostics.zsh,
                diagnostics.zsh,
                formatting.black,
                formatting.markdownlint,
                formatting.prettierd,
                formatting.shfmt,
                formatting.stylua,
                require("none-ls-shellcheck.code_actions"),
                require("none-ls-shellcheck.diagnostics"),
                require("none-ls.code_actions.eslint_d").with({ condition = has_eslint_config }),
                require("none-ls.diagnostics.eslint_d").with({ condition = has_eslint_config }),
                require("none-ls.formatting.eslint_d").with({ condition = has_eslint_config }),
                require("none-ls.formatting.jq"),
                require("none-ls.formatting.jq"),
            },
        })

        mason_null_ls.setup({
            ensure_installed = nil,
            automatic_installation = true,
            automatic_setup = false,
        })
    end,
}

(When switching eslint_d to eslint in the above config, everything works!)

Thanks for the awesome plugin!

mantoni commented 4 weeks ago

eslint_d: v14.0.3, bundled eslint: v9.8.0

This means that no local eslint was resolved and it falls back to the bundled version. Is there something wrong with the current working directory?

Also, do you have the same problem on the command line when running eslint_d <some-file>?

piersolenski commented 3 weeks ago

It does indeed seem to work with the command line, I guess the problem is coming via my Neovim setup, although it was working before 9, and doesn't include anything crazy?

I've also noticed if I change my eslint config to include an incorrect setting, using eslint via none-ls will offer a suggestion of how to fix it:

Oops! Something went wrong! :(ESLint: 9.9.0Configuration for rule "semi" is invalid. Expected severity of "off", 0, "warn", 1, "error", or 2.You passed '"never"'.See https://eslint.org/docs/latest/use/configure/rules#using-configuration-files for configuring rules. 1:1:14 eslint

eslint_d via none-ls just crashes:

failed to decode json: Expected value but found invalid token at character 1 1:1:3 eslint_d 

For anyone else experiencing issues with Neovim, for now I've switched to the eslint lsp and it seems pretty speedy:

require 'lspconfig'.eslint.setup({
  settings = {
    packageManager = 'yarn'
  },
  on_attach = function(client, bufnr)
    vim.api.nvim_create_autocmd("BufWritePre", {
      buffer = bufnr,
      command = "EslintFixAll",
    })
  end,
})
L2jLiga commented 1 week ago

Hi there, could you share your nvim start command and what is cwd?

I'm also using latest eslint_d via none-ls, but without any issues

piersolenski commented 1 week ago

It was simply nvim and whatever project I was working in.

L2jLiga commented 1 week ago

This is minimal config which is working fine on my end https://github.com/L2jLiga/nvim-none-ls-eslint_d

Tested with Windows 11 23H2 and Fedora 40