nvim-lint: added required files support

This commit is contained in:
rice-cracker-dev 2025-04-12 20:53:19 +07:00
commit a436aca603
6 changed files with 71 additions and 68 deletions

View file

@ -38,8 +38,29 @@ in {
{
event = ["BufWritePost"];
callback = mkLuaInline ''
function()
require("lint").try_lint()
function(args)
local ft = vim.api.nvim_get_option_value("filetype", { buf = args.buf })
local linters = require("lint").linters
local linters_from_ft = require("lint").linters_by_ft[ft]
-- if no linter is configured for this filetype, stops linting
if linters_from_ft == nil then return end
for _, name in ipairs(linters_from_ft) do
local cwd = linters[name].required_files
-- if no configuration files are configured, lint
if cwd == nil then
require("lint").try_lint(name)
else
-- if configuration files are configured and present in the project, lint
for _, fn in ipairs(cwd) do
if vim.uv.fs_stat(fn) then
require("lint").try_lint(name)
end
end
end
end
end
'';
}

View file

@ -69,6 +69,13 @@
default = null;
description = "Parser function";
};
required_files = mkOption {
type = nullOr (listOf str);
default = null;
description = "Required files to lint";
example = ["eslint.config.js"];
};
};
};
in {