nvim-lint: add linters option

This commit is contained in:
Ching Pei Yang 2025-03-27 16:32:44 +01:00
parent 6e8b6bf635
commit 7e1ffe40f5
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
2 changed files with 107 additions and 1 deletions

View file

@ -16,6 +16,18 @@ in {
startPlugins = ["nvim-lint"];
pluginRC.nvim-lint = entryAnywhere ''
require("lint").linters_by_ft = ${toLuaObject cfg.linters_by_ft}
local linters = require("lint").linters
local nvf_linters = ${toLuaObject cfg.linters}
for linter, config in pairs(nvf_linters) do
if linters[linter] == nil then
linters[linter] = config
else
for key, val in pairs(config) do
linters[linter][key] = val
end
end
end
'';
};
})

View file

@ -1,6 +1,76 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) attrsOf listOf str;
inherit (lib.types) nullOr attrsOf listOf str either submodule bool enum;
inherit (lib.nvim.types) luaInline;
linterType = submodule {
options = {
name = mkOption {
type = nullOr str;
default = null;
description = "Name of the linter";
};
cmd = mkOption {
type = nullOr str;
default = null;
description = "Command of the linter";
};
args = mkOption {
type = nullOr (listOf (either str luaInline));
default = null;
description = "Arguments to pass";
};
stdin = mkOption {
type = nullOr bool;
default = null;
description = "Send content via stdin.";
};
append_fname = mkOption {
type = nullOr bool;
default = null;
description = ''
Automatically add the current file name to the commands arguments. Only
has an effect if stdin is false
'';
};
stream = mkOption {
type = nullOr (enum ["stdout" "stderr" "both"]);
default = null;
description = "Result stream";
};
ignore_exitcode = mkOption {
type = nullOr bool;
default = null;
description = ''
Declares if exit code != 1 should be ignored or result in a warning.
'';
};
env = mkOption {
type = nullOr (attrsOf str);
default = null;
description = "Environment variables to use";
};
cwd = mkOption {
type = nullOr str;
default = null;
description = "Working directory of the linter";
};
parser = mkOption {
type = nullOr luaInline;
default = null;
description = "Parser function";
};
};
};
in {
options.vim.diagnostics.nvim-lint = {
enable = mkEnableOption "asynchronous linter plugin for Neovim [nvim-lint]";
@ -22,6 +92,30 @@ in {
'';
};
linters = mkOption {
type = attrsOf linterType;
default = {};
example = ''
{
phpcs = {
args = ["-q" "--report-json" "-"];
# this will replace the builtin's env table if it exists
env = {
ENV_VAR = "something";
};
};
}
'';
description = ''
Linter configurations. Builtin linters will be updated and not
replaced, but note that this is not a deep extend operation, i.e. if
you define an `env` option, it will replace the entire `env` table
provided by the builtin (if it exists).
'';
};
lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;};
};
}