-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathdetekt.nix
More file actions
77 lines (70 loc) · 1.98 KB
/
detekt.nix
File metadata and controls
77 lines (70 loc) · 1.98 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{
lib,
pkgs,
config,
mkFormatterModule,
...
}:
let
cfg = config.programs.detekt;
in
{
meta.maintainers = [
"raphiz"
];
imports = [
(mkFormatterModule {
name = "detekt";
args = [
"--auto-correct"
"--parallel"
];
includes = [
"*.kt"
"*.kts"
];
})
];
options.programs.detekt = {
configFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
example = "./detekt-config.yml";
description = "Path to detekt configuration file";
};
buildUponDefaultConfig = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Preconfigures detekt with a bunch of rules and some opinionated defaults for you. Allows additional provided configurations to override the defaults.";
};
};
config = lib.mkIf cfg.enable {
settings.formatter.detekt = {
options =
lib.optional (cfg.buildUponDefaultConfig) "--build-upon-default-config"
++ lib.optional (cfg.configFile != null) "--config"
++ lib.optional (cfg.configFile != null) "${cfg.configFile}";
command = pkgs.writeShellApplication {
name = "detekt-wrapper";
text = ''
# To pass the files to detect, they must be comma separated as follows: `detekt --input "a,b,c"`
# To build that string, we first skip all options passed to the wrapper and add them manually later.
skipN="${toString (builtins.length config.settings.formatter.detekt.options)}"
shift "$skipN"
# Join file paths into detekt's `--input "a,b,c"` format.
files=""
for f in "$@"; do
if [ -z "$files" ]; then
files="$f"
else
files="$files,$f"
fi
done
exec ${lib.getExe cfg.package} \
${lib.escapeShellArgs config.settings.formatter.detekt.options} \
--input "$files"
'';
};
};
};
}