nvim-lint: add lint after save autocmd

This commit is contained in:
Ching Pei Yang 2025-03-27 16:31:52 +01:00
parent aed996eb33
commit 6e8b6bf635
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
2 changed files with 29 additions and 9 deletions

View file

@ -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
'';
}
];
};
})
];
}

View file

@ -21,5 +21,7 @@ in {
accept.
'';
};
lint_after_save = mkEnableOption "autocmd to lint after each save" // {default = true;};
};
}