From 6e8b6bf6356a19f04b2d9fff73549f9d49e951be Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 27 Mar 2025 16:31:52 +0100 Subject: [PATCH] nvim-lint: add lint after save autocmd --- .../plugins/diagnostics/nvim-lint/config.nix | 36 ++++++++++++++----- .../diagnostics/nvim-lint/nvim-lint.nix | 2 ++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/plugins/diagnostics/nvim-lint/config.nix b/modules/plugins/diagnostics/nvim-lint/config.nix index 085140dc..5ecd8d70 100644 --- a/modules/plugins/diagnostics/nvim-lint/config.nix +++ b/modules/plugins/diagnostics/nvim-lint/config.nix @@ -3,18 +3,36 @@ lib, ... }: let - inherit (lib.modules) mkIf; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.generators) mkLuaInline; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.diagnostics.nvim-lint; in { - config = mkIf cfg.enable { - vim = { - startPlugins = ["nvim-lint"]; - pluginRC.nvim-lint = entryAnywhere '' - require("lint").linters_by_ft = ${toLuaObject cfg.linters_by_ft} - ''; - }; - }; + config = mkMerge [ + (mkIf cfg.enable { + vim = { + startPlugins = ["nvim-lint"]; + pluginRC.nvim-lint = entryAnywhere '' + require("lint").linters_by_ft = ${toLuaObject cfg.linters_by_ft} + ''; + }; + }) + (mkIf cfg.lint_after_save { + vim = { + augroups = [{name = "nvf_nvim_lint";}]; + autocmds = [ + { + event = ["BufWritePost"]; + callback = mkLuaInline '' + function() + require("lint").try_lint() + end + ''; + } + ]; + }; + }) + ]; } diff --git a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix index b08d82be..fc19d987 100644 --- a/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix +++ b/modules/plugins/diagnostics/nvim-lint/nvim-lint.nix @@ -21,5 +21,7 @@ in { accept. ''; }; + + lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;}; }; }