From cb6edd720229f189ecac26f4d21668bcadbc449d Mon Sep 17 00:00:00 2001 From: Vlad Lashko Date: Sun, 23 Jun 2024 07:57:49 +0000 Subject: [PATCH] feat: pass cwd to linter command --- lua/lint.lua | 6 +++--- lua/lint/linters/biomejs.lua | 9 +++++++-- lua/lint/linters/eslint.lua | 10 ++++++++-- lua/lint/linters/eslint_d.lua | 9 +++++++-- lua/lint/linters/markuplint.lua | 9 +++++++-- lua/lint/linters/prisma-lint.lua | 9 +++++++-- lua/lint/linters/stylelint.lua | 12 ++++++++++-- 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/lua/lint.lua b/lua/lint.lua index 23a93f7e..41da4bab 100644 --- a/lua/lint.lua +++ b/lua/lint.lua @@ -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 @@ -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 diff --git a/lua/lint/linters/biomejs.lua b/lua/lint/linters/biomejs.lua index 4ba5f1fb..9fd8cc78 100644 --- a/lua/lint/linters/biomejs.lua +++ b/lua/lint/linters/biomejs.lua @@ -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" }, diff --git a/lua/lint/linters/eslint.lua b/lua/lint/linters/eslint.lua index 706db097..380ede58 100644 --- a/lua/lint/linters/eslint.lua +++ b/lua/lint/linters/eslint.lua @@ -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 = { diff --git a/lua/lint/linters/eslint_d.lua b/lua/lint/linters/eslint_d.lua index 7a3ee2d6..e7f6df6a 100644 --- a/lua/lint/linters/eslint_d.lua +++ b/lua/lint/linters/eslint_d.lua @@ -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 = { diff --git a/lua/lint/linters/markuplint.lua b/lua/lint/linters/markuplint.lua index d0f58070..cbc3d787 100644 --- a/lua/lint/linters/markuplint.lua +++ b/lua/lint/linters/markuplint.lua @@ -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" }, diff --git a/lua/lint/linters/prisma-lint.lua b/lua/lint/linters/prisma-lint.lua index 942c58a5..6430b22c 100644 --- a/lua/lint/linters/prisma-lint.lua +++ b/lua/lint/linters/prisma-lint.lua @@ -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, diff --git a/lua/lint/linters/stylelint.lua b/lua/lint/linters/stylelint.lua index 4af24962..bcd7c616 100644 --- a/lua/lint/linters/stylelint.lua +++ b/lua/lint/linters/stylelint.lua @@ -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