-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathformatjson5.nix
55 lines (52 loc) · 1.35 KB
/
formatjson5.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
52
53
54
55
{
lib,
config,
mkFormatterModule,
...
}:
let
cfg = config.programs.formatjson5;
in
{
meta.maintainers = [ "katexochen" ];
imports = [
(mkFormatterModule {
name = "formatjson5";
args = [ "--replace" ];
includes = [ "*.json5" ];
})
];
options.programs.formatjson5 = {
noTrailingCommas = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Suppress trailing commas (otherwise added by default)";
};
oneElementLines = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Objects or arrays with a single child should collapse to a single line";
};
sortArrays = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Sort arrays of primitive values (string, number, boolean, or null) lexicographically";
};
indent = lib.mkOption {
type = lib.types.int;
default = 4;
description = "Indent by the given number of spaces";
};
};
config = lib.mkIf cfg.enable {
settings.formatter.formatjson5 = {
options =
[
"--indent=${toString cfg.indent}"
]
++ lib.optional cfg.noTrailingCommas "--no_trailing_commas"
++ lib.optional cfg.oneElementLines "--one_element_lines"
++ lib.optional cfg.sortArrays "--sort_arrays";
};
};
}