Skip to content

Commit

Permalink
feat: pass cwd to linter command
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderer199 committed Jul 2, 2024
1 parent efc6fc8 commit cb6edd7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
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

0 comments on commit cb6edd7

Please sign in to comment.