-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathstatix.nix
51 lines (47 loc) · 1.22 KB
/
statix.nix
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
{
lib,
pkgs,
config,
mkFormatterModule,
...
}:
let
cfg = config.programs.statix;
configFormat = pkgs.formats.toml { };
settingsFile = configFormat.generate "statix.toml" { disabled = cfg.disabled-lints; };
# statix requires its configuration file to be named statix.toml exactly
# See: https://github.com/nerdypepper/statix/pull/54
settingsDir = pkgs.runCommandLocal "statix-config" { } ''
mkdir "$out"
cp ${settingsFile} "''${out}/statix.toml"
'';
in
{
meta.maintainers = [ ];
imports = [
(mkFormatterModule {
name = "statix";
includes = [ "*.nix" ];
})
];
options.programs.statix = {
disabled-lints = lib.mkOption {
description = ''
List of ignored lints. Run `statix list` to see all available lints.
'';
type = with lib.types; listOf str;
example = [ "empty_pattern" ];
default = [ ];
};
};
config = lib.mkIf cfg.enable {
settings.formatter.statix = {
# statix doesn't support multiple file targets
command = pkgs.writeShellScriptBin "statix-fix" ''
for file in "$@"; do
${lib.getExe cfg.package} fix --config '${toString settingsDir}/statix.toml' "$file"
done
'';
};
};
}