Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use npm installed linter when available #519

Open
tobiabocchi opened this issue Jan 22, 2024 · 1 comment
Open

Use npm installed linter when available #519

tobiabocchi opened this issue Jan 22, 2024 · 1 comment

Comments

@tobiabocchi
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants