Compare commits

..

No commits in common. "92812036cce52687a9e089858d79f0e96c43c64c" and "6f3ad1f7269066ded5c2bbcf6f6b6b79dff8abf1" have entirely different histories.

6 changed files with 70 additions and 114 deletions

View file

@ -289,9 +289,7 @@
[rice-cracker-dev](https://github.com/rice-cracker-dev): [rice-cracker-dev](https://github.com/rice-cracker-dev):
- `eslint_d` now checks for configuration files to load. - `eslint_d` now checks for configuration files to load.
- Fix an error where `eslint_d` fails to load. - Fixed an error where `eslint_d` fails to load.
- Add required files support for linters under `vim.diagnostics.nvim-lint.linters.*.required_files`.
- Add global function `nvf_lint` under `vim.diagnostics.nvim-lint.lint_function`.
[Sc3l3t0n](https://github.com/Sc3l3t0n): [Sc3l3t0n](https://github.com/Sc3l3t0n):

View file

@ -28,8 +28,6 @@ in {
end end
end end
end end
nvf_lint = ${toLuaObject cfg.lint_function}
''; '';
}; };
}) })
@ -40,8 +38,8 @@ in {
{ {
event = ["BufWritePost"]; event = ["BufWritePost"];
callback = mkLuaInline '' callback = mkLuaInline ''
function(args) function()
nvf_lint(args.buf) require("lint").try_lint()
end end
''; '';
} }

View file

@ -1,8 +1,7 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum; inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum;
inherit (lib.nvim.types) luaInline; inherit (lib.nvim.types) luaInline;
inherit (lib.generators) mkLuaInline;
linterType = submodule { linterType = submodule {
options = { options = {
@ -70,23 +69,6 @@
default = null; default = null;
description = "Parser function"; description = "Parser function";
}; };
required_files = mkOption {
type = nullOr (listOf str);
default = null;
example = ["eslint.config.js"];
description = ''
Required files to lint. These files must exist relative to the cwd
of the linter or else this linter will be skipped
::: {.note}
This option is an nvf extension that only takes effect if you
use the `nvf_lint()` lua function.
See {option}`vim.diagnostics.nvim-lint.lint_function`.
:::
'';
};
}; };
}; };
in { in {
@ -135,53 +117,5 @@ in {
}; };
lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;}; lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;};
lint_function = mkOption {
type = luaInline;
default = mkLuaInline ''
function(buf)
local ft = vim.api.nvim_get_option_value("filetype", { buf = 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 linter = linters[name]
assert(linter, 'Linter with name `' .. name .. '` not available')
if type(linter) == "function" then
linter = linter()
end
-- for require("lint").lint() to work, linter.name must be set
linter.name = linter.name or name
local cwd = linter.required_files
-- if no configuration files are configured, lint
if cwd == nil then
require("lint").lint(linter)
else
-- if configuration files are configured and present in the project, lint
for _, fn in ipairs(cwd) do
local path = vim.fs.joinpath(linter.cwd or vim.fn.getcwd(), fn);
if vim.uv.fs_stat(path) then
require("lint").lint(linter)
break
end
end
end
end
end
'';
example = literalExpression ''
mkLuaInline '''
function(buf)
require("lint").try_lint()
end
'''
'';
description = "Define the global function nvf_lint which is used by nvf to lint.";
};
}; };
} }

View file

@ -53,20 +53,24 @@
# TODO: specify packages # TODO: specify packages
defaultDiagnosticsProvider = ["eslint_d"]; defaultDiagnosticsProvider = ["eslint_d"];
diagnosticsProviders = { diagnosticsProviders = {
eslint_d = let eslint_d = {
pkg = pkgs.eslint_d; package = pkgs.eslint_d;
in {
package = pkg;
config = { config = {
cmd = getExe pkg; # HACK: change if nvim-lint gets a dynamic enable thing
required_files = [ parser = mkLuaInline ''
"eslint.config.js" function(output, bufnr, cwd)
"eslint.config.mjs" local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc" ".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
".eslintrc.json" for _, filename in ipairs(markers) do
".eslintrc.js" local path = vim.fs.joinpath(cwd, filename)
".eslintrc.yml" if vim.loop.fs_stat(path) then
]; return require("lint.linters.eslint_d").parser(output, bufnr, cwd)
end
end
return {}
end
'';
}; };
}; };
}; };
@ -149,9 +153,16 @@ in {
vim.diagnostics.nvim-lint = { vim.diagnostics.nvim-lint = {
enable = true; enable = true;
linters_by_ft.astro = cfg.extraDiagnostics.types; linters_by_ft.astro = cfg.extraDiagnostics.types;
linters = linters = mkMerge (map (
mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;}) name: {
cfg.extraDiagnostics.types); ${name} =
diagnosticsProviders.${name}.config
// {
cmd = getExe diagnosticsProviders.${name}.package;
};
}
)
cfg.extraDiagnostics.types);
}; };
}) })
]); ]);

View file

@ -55,14 +55,21 @@
package = pkg; package = pkg;
config = { config = {
cmd = getExe pkg; cmd = getExe pkg;
required_files = [ # HACK: change if nvim-lint gets a dynamic enable thing
"eslint.config.js" parser = mkLuaInline ''
"eslint.config.mjs" function(output, bufnr, cwd)
".eslintrc" local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc.json" ".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
".eslintrc.js" for _, filename in ipairs(markers) do
".eslintrc.yml" local path = vim.fs.joinpath(cwd, filename)
]; if vim.loop.fs_stat(path) then
return require("lint.linters.eslint_d").parser(output, bufnr, cwd)
end
end
return {}
end
'';
}; };
}; };
}; };

View file

@ -91,20 +91,27 @@
# TODO: specify packages # TODO: specify packages
defaultDiagnosticsProvider = ["eslint_d"]; defaultDiagnosticsProvider = ["eslint_d"];
diagnosticsProviders = { diagnosticsProviders = {
eslint_d = let eslint_d = {
pkg = pkgs.eslint_d; package = pkgs.eslint_d;
in { config = let
package = pkg; pkg = pkgs.eslint_d;
config = { in {
cmd = getExe pkg; cmd = getExe pkg;
required_files = [ # HACK: change if nvim-lint gets a dynamic enable thing
"eslint.config.js" parser = mkLuaInline ''
"eslint.config.mjs" function(output, bufnr, cwd)
".eslintrc" local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc.json" ".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
".eslintrc.js" for _, filename in ipairs(markers) do
".eslintrc.yml" local path = vim.fs.joinpath(cwd, filename)
]; if vim.loop.fs_stat(path) then
return require("lint.linters.eslint_d").parser(output, bufnr, cwd)
end
end
return {}
end
'';
}; };
}; };
}; };
@ -214,9 +221,10 @@ in {
linters_by_ft.typescript = cfg.extraDiagnostics.types; linters_by_ft.typescript = cfg.extraDiagnostics.types;
linters_by_ft.typescriptreact = cfg.extraDiagnostics.types; linters_by_ft.typescriptreact = cfg.extraDiagnostics.types;
linters = linters = mkMerge (map (name: {
mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;}) ${name}.cmd = getExe diagnosticsProviders.${name}.package;
cfg.extraDiagnostics.types); })
cfg.extraDiagnostics.types);
}; };
}) })