Compare commits

...

14 commits

Author SHA1 Message Date
raf
92812036cc
Merge pull request #821 from rice-cracker-dev/lint-required-files
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions
nvim-lint: added required files support
2025-04-18 10:49:07 +00:00
rice-cracker-dev
05954eec6d docs: update vim.diagnostics.nvim-lint.*.required_files description 2025-04-18 11:00:16 +07:00
rice-cracker-dev
fd7c559ded Merge remote-tracking branch 'upstream/main' into lint-required-files 2025-04-17 20:35:23 +07:00
rice-cracker-dev
cdbf2ff370 Merge remote-tracking branch 'upstream/main' into lint-required-files 2025-04-15 22:31:10 +07:00
rice-cracker-dev
f830553166 nvim_lint: moved the function into a separate option "lint_function" 2025-04-14 18:01:52 +07:00
rice-cracker-dev
8961142817 Merge remote-tracking branch 'upstream/main' into lint-required-files 2025-04-14 16:54:37 +07:00
rice-cracker-dev
a3051d49aa format: formatted the project 2025-04-14 00:03:22 +07:00
rice-cracker-dev
acbeb26854 nvim-lint: moved linting into its own global function "nvf_lint(buf)" 2025-04-14 00:02:54 +07:00
rice-cracker-dev
1f8a44c432 Merge remote-tracking branch 'upstream/main' into lint-required-files 2025-04-13 23:08:17 +07:00
rice-cracker-dev
90d09ba05f nvim-lint: switch to .lint() 2025-04-13 20:57:23 +07:00
Phan Đăng Khoa
2b62a441e9
Update modules/plugins/diagnostics/nvim-lint/nvim-lint.nix
Co-authored-by: Ching Pei Yang <59727193+horriblename@users.noreply.github.com>
2025-04-13 16:07:27 +07:00
Phan Đăng Khoa
f4ee6a275f
Update modules/plugins/diagnostics/nvim-lint/config.nix
Co-authored-by: Ching Pei Yang <59727193+horriblename@users.noreply.github.com>
2025-04-13 16:06:58 +07:00
Phan Đăng Khoa
5c3a90e3f6
Update modules/plugins/diagnostics/nvim-lint/config.nix
Co-authored-by: Ching Pei Yang <59727193+horriblename@users.noreply.github.com>
2025-04-13 16:06:42 +07:00
rice-cracker-dev
a436aca603 nvim-lint: added required files support 2025-04-12 20:53:19 +07:00
6 changed files with 114 additions and 70 deletions

View file

@ -289,7 +289,9 @@
[rice-cracker-dev](https://github.com/rice-cracker-dev):
- `eslint_d` now checks for configuration files to load.
- Fixed an error where `eslint_d` fails to load.
- Fix 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):

View file

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

View file

@ -1,7 +1,8 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum;
inherit (lib.nvim.types) luaInline;
inherit (lib.generators) mkLuaInline;
linterType = submodule {
options = {
@ -69,6 +70,23 @@
default = null;
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 {
@ -117,5 +135,53 @@ in {
};
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,24 +53,20 @@
# TODO: specify packages
defaultDiagnosticsProvider = ["eslint_d"];
diagnosticsProviders = {
eslint_d = {
package = pkgs.eslint_d;
eslint_d = let
pkg = pkgs.eslint_d;
in {
package = pkg;
config = {
# HACK: change if nvim-lint gets a dynamic enable thing
parser = mkLuaInline ''
function(output, bufnr, cwd)
local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
for _, filename in ipairs(markers) do
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
'';
cmd = getExe pkg;
required_files = [
"eslint.config.js"
"eslint.config.mjs"
".eslintrc"
".eslintrc.json"
".eslintrc.js"
".eslintrc.yml"
];
};
};
};
@ -153,15 +149,8 @@ in {
vim.diagnostics.nvim-lint = {
enable = true;
linters_by_ft.astro = cfg.extraDiagnostics.types;
linters = mkMerge (map (
name: {
${name} =
diagnosticsProviders.${name}.config
// {
cmd = getExe diagnosticsProviders.${name}.package;
};
}
)
linters =
mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;})
cfg.extraDiagnostics.types);
};
})

View file

@ -55,21 +55,14 @@
package = pkg;
config = {
cmd = getExe pkg;
# HACK: change if nvim-lint gets a dynamic enable thing
parser = mkLuaInline ''
function(output, bufnr, cwd)
local markers = { "eslint.config.js", "eslint.config.mjs",
".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
for _, filename in ipairs(markers) do
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
'';
required_files = [
"eslint.config.js"
"eslint.config.mjs"
".eslintrc"
".eslintrc.json"
".eslintrc.js"
".eslintrc.yml"
];
};
};
};

View file

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