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

Ppass cwd to linter command #605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ function M.try_lint(names, opts)
running_procs_by_buf[bufnr] = running_procs
end

local function eval_fn_or_id(x)
local function eval_fn_or_id(x, opts)
if type(x) == 'function' then
return x()
return x(opts)
else
return x
end
Expand Down Expand Up @@ -321,7 +321,7 @@ function M.lint(linter, opts)
-- pop up shortly.
detached = not iswin
}
local cmd = eval_fn_or_id(linter.cmd)
local cmd = eval_fn_or_id(linter.cmd, opts)
assert(cmd, 'Linter definition must have a `cmd` set: ' .. vim.inspect(linter))
handle, pid_or_err = uv.spawn(cmd, linter_opts, function(code)
if handle and not handle:is_closing() then
Expand Down
9 changes: 7 additions & 2 deletions lua/lint/linters/biomejs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
local binary_name = "biome"

return {
cmd = function()
local local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
cmd = function(opts)
local local_binary;
if opts.cwd then
local_binary = vim.fn.fnamemodify(opts.cwd .. '/node_modules/.bin/' .. binary_name, ':p')
else
local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
end
return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,
args = { "lint" },
Expand Down
10 changes: 8 additions & 2 deletions lua/lint/linters/eslint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ local severities = {
}

return {
cmd = function()
local local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
cmd = function(opts)
local local_binary;
if opts.cwd then
local_binary = vim.fn.fnamemodify(opts.cwd .. '/node_modules/.bin/' .. binary_name, ':p')
else
local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
end

return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,
args = {
Expand Down
9 changes: 7 additions & 2 deletions lua/lint/linters/eslint_d.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
local binary_name = "eslint_d"
return {
cmd = function()
local local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
cmd = function(opts)
local local_binary;
if opts.cwd then
local_binary = vim.fn.fnamemodify(opts.cwd .. '/node_modules/.bin/' .. binary_name, ':p')
else
local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
end
return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,
args = {
Expand Down
9 changes: 7 additions & 2 deletions lua/lint/linters/markuplint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ local severity_map = {
}

return {
cmd = function()
local local_binary = vim.fn.fnamemodify("./node_modules/.bin/" .. binary_name, ":p")
cmd = function(opts)
local local_binary;
if opts.cwd then
local_binary = vim.fn.fnamemodify(opts.cwd .. '/node_modules/.bin/' .. binary_name, ':p')
else
local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
end
return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,
args = { "--format", "JSON" },
Expand Down
9 changes: 7 additions & 2 deletions lua/lint/linters/prisma-lint.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
local binary_name = "prisma-lint"

return {
cmd = function()
local local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
cmd = function(opts)
local local_binary;
if opts.cwd then
local_binary = vim.fn.fnamemodify(opts.cwd .. '/node_modules/.bin/' .. binary_name, ':p')
else
local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
end
return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,
stdin = false,
Expand Down
12 changes: 10 additions & 2 deletions lua/lint/linters/stylelint.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
local binary_name = "stylelint"

local severities = {
warning = vim.diagnostic.severity.WARN,
error = vim.diagnostic.severity.ERROR,
}

return {
cmd = function()
local local_stylelint = vim.fn.fnamemodify("./node_modules/.bin/stylelint", ":p")
cmd = function(opts)
local local_stylelint;
if opts.cwd then
local_stylelint = vim.fn.fnamemodify(opts.cwd .. '/node_modules/.bin/' .. binary_name, ':p')
else
local_stylelint = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
end

local stat = vim.loop.fs_stat(local_stylelint)
if stat then
return local_stylelint
Expand Down