Skip to content

Commit 8dbc2d7

Browse files
committed
chore: treefmt support
1 parent 49127b6 commit 8dbc2d7

File tree

8 files changed

+42
-45
lines changed

8 files changed

+42
-45
lines changed

.config/flakebox/id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
73cf0906ef0f6cf3d29caed7d58a7f826172d3ee593ad3510289eee2937ecd4d71074d62b0c327a7e026fd61d96d09c0b43fc40d7934b2a61fc85dbee554c210
1+
50a671ba231a9589bee8dda3a8604e8e7304d1da0373a008a653f8000d06ba0f203accf8c0c123223a70b6b032037e4c79240f61dd0fb5046b0fe55aba5b4778

.treefmt.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[formatter.nix]
2+
command = "nixfmt"
3+
includes = ["*.nix"]
4+
5+
[formatter.rust]
6+
command = "rustfmt"
7+
options = ["--edition", "2024"]
8+
includes = ["*.rs"]

flakebox-bin/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod opts;
22

3-
use std::fs::{set_permissions, Permissions};
3+
use std::fs::{Permissions, set_permissions};
44
use std::io;
55
use std::os::unix::fs::PermissionsExt;
66
use std::path::{Path, PathBuf};

lib/mkDevShell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ let
8383
coreutils
8484
parallel
8585
shellcheck
86+
treefmt
8687
;
8788
# Nix
8889
inherit (pkgs) nixfmt-rfc-style nil;

lib/mkLintShell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ let
6464
coreutils
6565
parallel
6666
shellcheck
67+
treefmt
6768
;
6869
# Nix
6970
inherit (pkgs) nixfmt-rfc-style;

lib/modules/nix.nix

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/modules/treefmt.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{ lib, config, ... }:
2+
let
3+
inherit (lib) types;
4+
in
5+
{
6+
options.treefmt = {
7+
enable = lib.mkEnableOption "clippy check in pre-commit hook" // {
8+
default = true;
9+
};
10+
};
11+
12+
config = lib.mkMerge [
13+
(lib.mkIf config.treefmt.enable {
14+
git.pre-commit.hooks = {
15+
treefmt = ''
16+
treefmt -q --fail-on-change
17+
'';
18+
};
19+
})
20+
];
21+
}

misc/git-hooks/pre-commit

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ function check_cargo_lock() {
6060
}
6161
export -f check_cargo_lock
6262

63-
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
64-
function check_nixfmt() {
65-
set -euo pipefail
66-
67-
# we actually rely on word splitting here
68-
# shellcheck disable=SC2046
69-
nixfmt -c $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep "\.nix$")
70-
}
71-
export -f check_nixfmt
72-
7363
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
7464
function check_semgrep() {
7565
set -euo pipefail
@@ -148,6 +138,14 @@ function check_trailing_whitespace() {
148138
}
149139
export -f check_trailing_whitespace
150140

141+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
142+
function check_treefmt() {
143+
set -euo pipefail
144+
145+
treefmt -q --fail-on-change
146+
}
147+
export -f check_treefmt
148+
151149
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
152150
function check_typos() {
153151
set -euo pipefail
@@ -164,11 +162,11 @@ parallel \
164162
::: \
165163
check_cargo_fmt \
166164
check_cargo_lock \
167-
check_nixfmt \
168165
check_semgrep \
169166
check_shellcheck \
170167
check_trailing_newline \
171168
check_trailing_whitespace \
169+
check_treefmt \
172170
check_typos \
173171
check_nothing
174172
#

0 commit comments

Comments
 (0)