Repository navigation
Expand file tree
/
Copy pathjson-sort-cli.nix
More file actions
112 lines (104 loc) · 2.62 KB
/
Copy pathjson-sort-cli.nix
File metadata and controls
112 lines (104 loc) · 2.62 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
lib,
pkgs,
config,
mkFormatterModule,
...
}:
let
cfg = config.programs.json-sort-cli;
in
{
meta = {
# Example contains store paths
skipExample = true;
maintainers = [ ];
};
imports = [
(mkFormatterModule {
name = "json-sort-cli";
package = "json-sort-cli";
mainProgram = "json-sort";
includes = [
"*.json"
];
})
];
options.programs.json-sort-cli = {
autofix = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Update files with fixes instead of just reporting.
Defaults to `false`.
'';
};
insert-final-newline = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Insert a final newline after the sort. Defaults to `false`.
Overrides `.editorconfig` settings if an `.editorconfig` is found.
'';
};
end-of-line = lib.mkOption {
type = lib.types.nullOr (
lib.types.enum [
"lf"
"crlf"
"cr"
"unset"
]
);
default = null;
description = ''
Specify the desired line ending for output.
Defaults to system line ending.
Overrides `.editorconfig` settings if an `.editorconfig` is found.
'';
};
indent-style = lib.mkOption {
type = lib.types.enum [
"space"
"tab"
];
default = "space";
description = ''
Specify the desired indentation style for output.
Defaults to `space`. Overrides `.editorconfig` settings if an `.editorconfig` is found.
'';
};
indent-size = lib.mkOption {
type = lib.types.int;
default = 2;
description = ''
Number of spaces to indent, or the string "tab" to use tabs.
Defaults to 2 spaces. Overrides `.editorconfig` settings if an `.editorconfig` is found.
'';
};
};
config = lib.mkIf cfg.enable {
settings.formatter.json-sort-cli = {
command = pkgs.bash;
options = [
"-euc"
(
''
for f in "$@"; do
${lib.getExe cfg.package} $f \
--autofix ${if cfg.autofix == true then "true" else "false"} \
--insert-final-newline ${if cfg.insert-final-newline == true then "true" else "false"} \
''
+ (lib.optionalString (cfg.end-of-line != null) "--end-of-line ${cfg.end-of-line}")
+ ''
\
--indent-style ${cfg.indent-style} \
--indent-size ${toString cfg.indent-size} || true
done
''
)
"--"
];
};
};
}