forked from cachix/git-hooks.nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.nix
309 lines (308 loc) · 9.55 KB
/
hooks.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
{ config, lib, pkgs, ... }:
let
inherit (config) tools settings;
inherit (lib) mkOption types;
in
{
options.settings =
{
hpack =
{
silent =
mkOption {
type = types.bool;
description = "Should generation should be silent";
default = false;
};
};
ormolu =
{
defaultExtensions =
mkOption {
type = types.listOf types.str;
description = "Haskell language extensions to enable";
default = [ ];
};
};
nix-linter =
{
checks =
mkOption {
type = types.listOf types.str;
description =
"Available checks (See `nix-linter --help-for [CHECK]` for more details)";
default = [ ];
};
};
prettier =
{
binPath =
mkOption {
type = types.path;
description =
"Prettier binary path. E.g. if you want to use the prettier in node_modules, use ./node_modules/.bin/prettier";
default = "${tools.prettier}/bin/prettier";
};
};
};
config.hooks =
{
ansible-lint =
{
name = "ansible-lint";
description =
"Ansible linter";
entry = "${tools.ansible-lint}/bin/ansible-lint";
};
black =
{
name = "black";
description = "The uncompromising Python code formatter";
entry = "${pkgs.python3Packages.black}/bin/black";
types = [ "file" "python" ];
};
clang-format =
{
name = "clang-format";
description = "Format your code using clang-format";
entry = "${tools.clang-tools}/bin/clang-format -style=file -i";
types = [ "file" ];
};
brittany =
{
name = "brittany";
description = "Haskell source code formatter.";
entry = "${tools.brittany}/bin/brittany --write-mode=inplace";
files = "\\.l?hs$";
};
hlint =
{
name = "hlint";
description =
"HLint gives suggestions on how to improve your source code.";
entry = "${tools.hlint}/bin/hlint";
files = "\\.l?hs$";
};
hpack =
{
name = "hpack";
description =
"hpack converts package definitions in the hpack format (package.yaml) to Cabal files.";
entry = "${tools.hpack-dir}/bin/hpack-dir --${if settings.hpack.silent then "silent" else "verbose"}";
files = "(\\.l?hs$)|(^[^/]+\\.cabal$)|(^package\\.yaml$)";
};
isort =
{
name = "isort";
description = "A Python utility / library to sort imports.";
entry = "${pkgs.python3Packages.isort}/bin/isort";
types = [ "file" "python" ];
};
ormolu =
{
name = "ormolu";
description = "Haskell code prettifier.";
entry =
"${tools.ormolu}/bin/ormolu --mode inplace ${
lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) settings.ormolu.defaultExtensions)
}";
files = "\\.l?hs$";
};
fourmolu =
{
name = "fourmolu";
description = "Haskell code prettifier.";
entry =
"${tools.fourmolu}/bin/fourmolu --mode inplace ${
lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) settings.ormolu.defaultExtensions)
}";
files = "\\.l?hs$";
};
hindent =
{
name = "hindent";
description = "Haskell code prettifier.";
entry = "${tools.hindent}/bin/hindent";
files = "\\.l?hs$";
};
cabal-fmt =
{
name = "cabal-fmt";
description = "Format Cabal files";
entry = "${tools.cabal-fmt}/bin/cabal-fmt --inplace";
files = "\\.cabal$";
};
stylish-haskell =
{
name = "stylish-haskell";
description = "A simple Haskell code prettifier";
entry = "${tools.stylish-haskell}/bin/stylish-haskell --inplace";
files = "\\.l?hs$";
};
nixfmt =
{
name = "nixfmt";
description = "Nix code prettifier.";
entry = "${tools.nixfmt}/bin/nixfmt";
files = "\\.nix$";
};
nixpkgs-fmt =
{
name = "nixpkgs-fmt";
description = "Nix code prettifier.";
entry = "${tools.nixpkgs-fmt}/bin/nixpkgs-fmt";
files = "\\.nix$";
};
nix-linter =
{
name = "nix-linter";
description = "Linter for the Nix expression language.";
entry =
"${tools.nix-linter}/bin/nix-linter ${
lib.escapeShellArgs (lib.concatMap (check: [ "-W" "${check}" ]) settings.nix-linter.checks)
}";
files = "\\.nix$";
};
elm-format =
{
name = "elm-format";
description = "Format Elm files";
entry =
"${tools.elm-format}/bin/elm-format --yes --elm-version=0.19";
files = "\\.elm$";
};
elm-review =
{
name = "elm-review";
description = "Analyzes Elm projects, to help find mistakes before your users find them.";
entry = "${tools.elm-review}/bin/elm-review";
files = "\\.elm$";
pass_filenames = false;
};
elm-test =
{
name = "elm-review";
description = "Run unit and fuzz tests for Elm code.";
entry = "${tools.elm-test}/bin/elm-test";
files = "\\.elm$";
pass_filenames = false;
};
shellcheck =
{
name = "shellcheck";
description = "Format shell files";
types = [ "shell" ];
types_or =
# based on `goodShells` in https://github.com/koalaman/shellcheck/blob/master/src/ShellCheck/Parser.hs
[
"sh"
"ash"
"bash"
"bats"
"dash"
"ksh"
];
entry = "${tools.shellcheck}/bin/shellcheck";
};
terraform-format =
{
name = "terraform-format";
description = "Format terraform (.tf) files";
entry = "${tools.terraform-fmt}/bin/terraform-fmt";
files = "\\.tf$";
};
yamllint =
{
name = "yamllint";
description = "Yaml linter";
types = [ "file" "yaml" ];
entry = "${tools.yamllint}/bin/yamllint";
};
rustfmt =
{
name = "rustfmt";
description = "Format Rust code.";
entry = "${tools.rustfmt}/bin/cargo-fmt fmt -- --check --color always";
files = "\\.rs$";
pass_filenames = false;
};
clippy =
{
name = "clippy";
description = "Lint Rust code.";
entry = "${tools.clippy}/bin/cargo-clippy clippy";
files = "\\.rs$";
pass_filenames = false;
};
cargo-check =
{
name = "cargo-check";
description = "Check the cargo package for errors";
entry = "${tools.cargo}/bin/cargo check";
files = "\\.rs$";
pass_filenames = false;
};
purty =
{
name = "purty";
description = "Format purescript files";
entry = "${tools.purty}/bin/purty";
files = "\\.purs$";
};
prettier =
{
name = "prettier";
description = "Opinionated multi-language code formatter";
entry = "${settings.prettier.binPath} --write --list-different --ignore-unknown";
types = [ "text" ];
};
hunspell =
{
name = "hunspell";
description = "Spell checker and morphological analyzer";
entry = "${tools.hunspell}/bin/hunspell -l";
files = "\\.((txt)|(html)|(xml)|(md)|(rst)|(tex)|(odf)|\\d)$";
};
html-tidy =
{
name = "html-tidy";
description = "HTML linter";
entry = "${tools.html-tidy}/bin/tidy -quiet -errors";
files = "\\.html$";
};
trailing-whitespace =
{
name = "trim trailing whitespace";
description = "trims trailing whitespace.";
entry = "${pkgs.python39Packages.pre-commit-hooks}/bin/trailing-whitespace-fixer";
language = "python";
types = [ "text" ];
stages = [ "commit" "push" "manual" ];
};
end-of-file-fixer =
{
name = "fix end of files";
description = "ensures that a file is either empty, or ends with one newline.";
entry = "${pkgs.python39Packages.pre-commit-hooks}/bin/end-of-file-fixer";
language = "python";
types = [ "text" ];
stages = [ "commit" "push" "manual" ];
};
check-yaml =
{
name = "check yaml";
description = "checks yaml files for parseable syntax.";
entry = "${pkgs.python39Packages.pre-commit-hooks}/bin/check-yaml";
language = "python";
types = [ "yaml" ];
};
check-merge-conflict =
{
name = "check for merge conflicts";
description = " checks for files that contain merge conflict strings.";
entry = "${pkgs.python39Packages.pre-commit-hooks}/bin/check-merge-conflict";
language = "python";
types = [ "text" ];
};
};
}