blob: 16e6b19b546d5ba53e936ea605a09947af0a3678 (
plain) (
blame)
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
|
# Builds treefmt for depot, with a hardcoded configuration that
# includes the right paths to formatters.
{ pkgs, ... }:
let
config = pkgs.writeText "depot-treefmt-config" ''
[formatter.go]
command = "${pkgs.go}/bin/gofmt"
options = [ "-w" ]
includes = ["*.go"]
[formatter.nix]
command = "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
includes = [ "*.nix" ]
excludes = [
"tvix/eval/src/tests/nix_tests/*",
]
[formatter.rust]
command = "${pkgs.rustfmt}/bin/rustfmt"
options = ["--edition", "2021"]
includes = [ "*.rs" ]
excludes = [
"users/tazjin/*",
]
'';
# helper tool for formatting the depot interactively
depotfmt = pkgs.writeShellScriptBin "depotfmt" ''
exec ${pkgs.treefmt}/bin/treefmt ''${@} \
--on-unmatched=debug \
--config-file=${config} \
--tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel)
'';
# wrapper script for running formatting checks in CI
check = pkgs.writeShellScript "depotfmt-check" ''
${pkgs.treefmt}/bin/treefmt \
--no-cache \
--on-unmatched=debug \
--fail-on-change \
--config-file=${config} \
--tree-root=.
'';
in
depotfmt.overrideAttrs (_: {
passthru = {
inherit config check;
meta.ci.extraSteps.check = {
label = "depot formatting check";
command = check;
alwaysRun = true;
};
};
})
|