Search code examples
eslintneovimlinternone-ls

problem with eslint_d in neovim (none-ls)


I am having a problem with eslint_d in Neovim, where it only seems to work with json, whenever I open a Javascript or Typescript file, I get an error in the very first line even if the file is empty:

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

The linter doesn't seem to work as well, for example code like this won't generate an error or a warning:

"use strict";
a = 10; // should trigger an error: 'x' is not defined

Here's my current none-ls configuration:

return {
    "nvimtools/none-ls.nvim",
    dependencies = {
        "nvimtools/none-ls-extras.nvim",
    },
    config = function()
        local null_ls = require("null-ls")
        null_ls.setup({
            sources = {
                require("none-ls.diagnostics.eslint_d"),
                null_ls.builtins.formatting.stylua,
                null_ls.builtins.formatting.prettier,
                null_ls.builtins.formatting.black,
                null_ls.builtins.formatting.isort,
                null_ls.builtins.formatting.clang_format,
                null_ls.builtins.formatting.google_java_format,
                null_ls.builtins.diagnostics.checkstyle,
                null_ls.builtins.diagnostics.cppcheck,
                null_ls.builtins.diagnostics.stylelint,
            },
        })
        vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, {})
    end,
}

I have looked everywhere for a solution but couldn't find anything, i also tried switching to oxlint and biome by installing them through Mason and modifying the configuration like this:

return {
    "nvimtools/none-ls.nvim",
    dependencies = {
        "nvimtools/none-ls-extras.nvim",
    },
    config = function()
        local null_ls = require("null-ls")
        null_ls.setup({
            sources = {
                null_ls.builtins.diagnostics.oxlint,
                -- or
                null_ls.builtins.diagnostics.biome  

                null_ls.builtins.formatting.stylua,
                null_ls.builtins.formatting.prettier,
                null_ls.builtins.formatting.black,
                null_ls.builtins.formatting.isort,
                null_ls.builtins.formatting.clang_format,
                null_ls.builtins.formatting.google_java_format,
                null_ls.builtins.diagnostics.checkstyle,
                null_ls.builtins.diagnostics.cppcheck,
                null_ls.builtins.diagnostics.stylelint,
            },
        })
        vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, {})
    end,
}

but both didn't work for some reason, and i kept getting an error:

[null-ls] failed to load builtin oxlint for method diagnostics; please check your config

Does anyone know what the problem with eslint_d is? or how can i switch to oxlint or biome instead? Thanks a lot!


Solution

  • I know nothing about none-ls, but since you asked about how to setup biome or oxlint:

    Both biome and oxlint can be use as language servers, so you can set them with lspconfig, check kickstart.nvim as an example. They will also work as formatters without needing an additional formatting plugin.

    Basically you install lspconfig, and mason; and set the servers like this and pass the capabilities, on_attach, settings, etc. to the setup table:

    require("lspconfig").biome.setup({
        on_attach = ...,
        capabilities = ...,
        settings = ...,
    })
    

    I really recommend you to check kickstart.nvim for a better example.

    Funnily enough, you can do the same with eslint by installing eslint_lsp provided you want to stick with eslint, so in the end none-ls becomes irrelevant.