From fe9ae6c6ed9752f01a85079994bb13ab0d241a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Sat, 10 Jan 2026 22:09:03 -0800 Subject: [PATCH] chore: treefmt support --- .config/flakebox/id | 2 +- .rustfmt.toml | 2 +- .treefmt.toml | 8 ++++++++ Cargo.toml | 2 +- flakebox-bin/src/main.rs | 2 +- lib/mkDevShell.nix | 1 + lib/mkLintShell.nix | 1 + lib/modules/nix.nix | 32 -------------------------------- lib/modules/rust.nix | 2 +- lib/modules/treefmt.nix | 21 +++++++++++++++++++++ misc/git-hooks/pre-commit | 20 +++++++++----------- 11 files changed, 45 insertions(+), 48 deletions(-) create mode 100644 .treefmt.toml delete mode 100644 lib/modules/nix.nix create mode 100644 lib/modules/treefmt.nix diff --git a/.config/flakebox/id b/.config/flakebox/id index ce66bf7..36aaf48 100644 --- a/.config/flakebox/id +++ b/.config/flakebox/id @@ -1 +1 @@ -73cf0906ef0f6cf3d29caed7d58a7f826172d3ee593ad3510289eee2937ecd4d71074d62b0c327a7e026fd61d96d09c0b43fc40d7934b2a61fc85dbee554c210 +2fefc36adbe89c5c8953715f73d8c3d75062ecf9937b22e9b88afaa9cb261fc5bea72e092566df9803b7948b186f39abf7458504c35de64f5dec352a4e14d80d diff --git a/.rustfmt.toml b/.rustfmt.toml index 35cd282..c3e078c 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -2,4 +2,4 @@ group_imports = "StdExternalCrate" wrap_comments = true format_code_in_doc_comments = true imports_granularity = "Module" -edition = "2021" +edition = "2024" diff --git a/.treefmt.toml b/.treefmt.toml new file mode 100644 index 0000000..0222a7f --- /dev/null +++ b/.treefmt.toml @@ -0,0 +1,8 @@ +[formatter.nix] +command = "nixfmt" +includes = ["*.nix"] + +[formatter.rust] +command = "rustfmt" +options = ["--edition", "2024", "--config", "skip_children=true"] +includes = ["*.rs"] diff --git a/Cargo.toml b/Cargo.toml index 1b1a574..855e40c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] version = "0.1.0" authors = ["Dawid Ciężarkiewicz "] -edition = "2021" +edition = "2024" description = "Rust dev experience (DX) we can share and love." documentation = "https://github.com/rustshop/flakebox" readme = "README.md" diff --git a/flakebox-bin/src/main.rs b/flakebox-bin/src/main.rs index 5da7d07..b84e7d7 100644 --- a/flakebox-bin/src/main.rs +++ b/flakebox-bin/src/main.rs @@ -1,6 +1,6 @@ mod opts; -use std::fs::{set_permissions, Permissions}; +use std::fs::{Permissions, set_permissions}; use std::io; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; diff --git a/lib/mkDevShell.nix b/lib/mkDevShell.nix index 3408c60..cd7fab8 100644 --- a/lib/mkDevShell.nix +++ b/lib/mkDevShell.nix @@ -83,6 +83,7 @@ let coreutils parallel shellcheck + treefmt ; # Nix inherit (pkgs) nixfmt-rfc-style nil; diff --git a/lib/mkLintShell.nix b/lib/mkLintShell.nix index 51ff984..6a52f04 100644 --- a/lib/mkLintShell.nix +++ b/lib/mkLintShell.nix @@ -64,6 +64,7 @@ let coreutils parallel shellcheck + treefmt ; # Nix inherit (pkgs) nixfmt-rfc-style; diff --git a/lib/modules/nix.nix b/lib/modules/nix.nix deleted file mode 100644 index 896a45b..0000000 --- a/lib/modules/nix.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ lib, config, ... }: -let - inherit (lib) types; -in -{ - - options.nix = { - nixfmt = { - enable = lib.mkEnableOption "nixfmt support" // { - default = true; - }; - - pre-commit = { - enable = lib.mkEnableOption "check nixfmt in pre-commit hook" // { - default = true; - }; - }; - }; - }; - - config = lib.mkMerge [ - (lib.mkIf (config.nix.nixfmt.enable && config.nix.nixfmt.pre-commit.enable) { - git.pre-commit.hooks = { - nixfmt = '' - # we actually rely on word splitting here - # shellcheck disable=SC2046 - nixfmt -c $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep "\.nix$") - ''; - }; - }) - ]; -} diff --git a/lib/modules/rust.nix b/lib/modules/rust.nix index 9da77b7..5003ae5 100644 --- a/lib/modules/rust.nix +++ b/lib/modules/rust.nix @@ -50,7 +50,7 @@ in wrap_comments = true format_code_in_doc_comments = true imports_granularity = "Module" - edition = "2021" + edition = "2024" ''; }) diff --git a/lib/modules/treefmt.nix b/lib/modules/treefmt.nix new file mode 100644 index 0000000..7ad0668 --- /dev/null +++ b/lib/modules/treefmt.nix @@ -0,0 +1,21 @@ +{ lib, config, ... }: +let + inherit (lib) types; +in +{ + options.treefmt = { + enable = lib.mkEnableOption "clippy check in pre-commit hook" // { + default = true; + }; + }; + + config = lib.mkMerge [ + (lib.mkIf config.treefmt.enable { + git.pre-commit.hooks = { + treefmt = '' + treefmt -q --fail-on-change + ''; + }; + }) + ]; +} diff --git a/misc/git-hooks/pre-commit b/misc/git-hooks/pre-commit index 74b1ebb..7897815 100755 --- a/misc/git-hooks/pre-commit +++ b/misc/git-hooks/pre-commit @@ -60,16 +60,6 @@ function check_cargo_lock() { } export -f check_cargo_lock -# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX -function check_nixfmt() { - set -euo pipefail - - # we actually rely on word splitting here - # shellcheck disable=SC2046 - nixfmt -c $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep "\.nix$") -} -export -f check_nixfmt - # NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX function check_semgrep() { set -euo pipefail @@ -148,6 +138,14 @@ function check_trailing_whitespace() { } export -f check_trailing_whitespace +# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX +function check_treefmt() { + set -euo pipefail + + treefmt -q --fail-on-change +} +export -f check_treefmt + # NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX function check_typos() { set -euo pipefail @@ -164,11 +162,11 @@ parallel \ ::: \ check_cargo_fmt \ check_cargo_lock \ - check_nixfmt \ check_semgrep \ check_shellcheck \ check_trailing_newline \ check_trailing_whitespace \ + check_treefmt \ check_typos \ check_nothing #