mfussenegger / nvim-lint

An asynchronous linter plugin for Neovim complementary to the built-in Language Server Protocol support.
GNU General Public License v3.0
1.94k stars 204 forks source link

Use npm installed linter when available #519

Open tobiabocchi opened 8 months ago

tobiabocchi commented 8 months ago

Hey! thanks for all this work, I have been using your repo for a few days and I really like it!

I am trying to work with a js project which uses a specific version of standardjs, I noticed that it nvim-lint was not picking that one but the one installed system wide instead..

For formatting I am using conform.nvim which I think handles this correctly through a util method:

here is the code that sets up standardjs as formatter, to parse the command to use it uses this util method.

I thought this might come in handy for a few linters in your project and maybe worth including.. I am not very experienced in lua, I mainly just use it to set up neovim.. If you don't have the time or don't think this is a priority I can try adding it myself and open a PR

AbelAnaya commented 1 month ago

Hello!

I achieved this behavior by reusing some code of the eslint linter configuration in this project.

You can select how a linter behaves by modifying its properties in your configuration file for the plugin. An example for standard:

local lint = require("lint")
local binary_name = "standard"

local cmd_string = function()
    local local_binary = vim.fn.fnamemodify("./node_modules/.bin/" .. binary_name, ":p")
    return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end

-- Use always local standard
local standardjs = lint.linters.standardjs
standardjs.cmd = cmd_string()

Simply add this code to your configuration function and nvim-lint will start using standardjs from local node_modules if possible, if not it will fallback to system wide installation.

I will try to add a PR that integrates the utils method of conform and uses it for standardjsin that project.