From 7e1ffe40f519f31e8b22a4900c3b11d980d231ef Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 27 Mar 2025 16:32:44 +0100 Subject: [PATCH] nvim-lint: add linters option --- .../plugins/diagnostics/nvim-lint/config.nix | 12 +++ .../diagnostics/nvim-lint/nvim-lint.nix | 96 ++++++++++++++++++- 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/modules/plugins/diagnostics/nvim-lint/config.nix b/modules/plugins/diagnostics/nvim-lint/config.nix index 5ecd8d70..cf9c45e2 100644 --- a/modules/plugins/diagnostics/nvim-lint/config.nix +++ b/modules/plugins/diagnostics/nvim-lint/config.nix @@ -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 ''; }; }) diff --git a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix index fc19d987..20f14f0b 100644 --- a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix +++ b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix @@ -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;}; }; }