summaryrefslogtreecommitdiffstats
path: root/modules/plugins/diagnostics/nvim-lint/config.nix
blob: 488bd70f31d4eb95a926c97725e8b4ed58665eb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
  config,
  lib,
  ...
}: let
  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 = mkMerge [
    (mkIf cfg.enable {
      vim = {
        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

          nvf_lint = ${toLuaObject cfg.lint_function}
        '';
      };
    })
    (mkIf (cfg.enable && cfg.lint_after_save) {
      vim = {
        augroups = [{name = "nvf_nvim_lint";}];
        autocmds = [
          {
            event = ["BufWritePost"];
            callback = mkLuaInline ''
              function(args)
                nvf_lint(args.buf)
              end
            '';
          }
        ];
      };
    })
  ];
}