From 17fe4f88a86e416e80d85a4dad2dacf21feeccde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Wed, 24 Jun 2026 22:21:29 +0200 Subject: [PATCH] Use treefmt to drive all formatters - Replace the per-tool format invocations with treefmt (devenv's treefmt-nix integration): Ruby via syntax_tree, SQL via sqlfluff, configured in devenv.nix. - Exclude sqlfluff's LT05 (line too long) so `sqlfluff format` exits 0 as a formatter; the long lines it can't wrap no longer fail it. - Point app:format and the Claude on-save hook at treefmt (SQL now formats on save too), drop the Rakefile format task, and update AGENTS.md. --- .sqlfluff | 4 ++++ AGENTS.md | 2 +- Rakefile | 5 ----- devenv.lock | 23 ++++++++++++++++++++++- devenv.nix | 26 ++++++++++++++++++++++---- devenv.yaml | 9 +++++++-- 6 files changed, 56 insertions(+), 13 deletions(-) diff --git a/.sqlfluff b/.sqlfluff index 7fb4ec3..391f553 100644 --- a/.sqlfluff +++ b/.sqlfluff @@ -1,2 +1,6 @@ [sqlfluff] dialect = postgres +# LT05 (line too long) is unfixable for long function signatures and seed +# rows, which makes `sqlfluff format` exit non-zero. Exclude it so it acts +# purely as a formatter under treefmt. +exclude_rules = LT05 diff --git a/AGENTS.md b/AGENTS.md index 6495684..4cc278e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,5 +1,5 @@ # Agent rules - Prefer inlining variables when they are not reused. -- After editing files, run `bin/rake format`. +- After editing files, run `treefmt`. - When adding and building a feature, follow the TDD process. diff --git a/Rakefile b/Rakefile index 9e39bb4..eead8d7 100644 --- a/Rakefile +++ b/Rakefile @@ -6,11 +6,6 @@ require_relative "lib/en57/tasks" Minitest::TestTask.create -task :format do - system("stree write **/*.rb") - system("sqlfluff format db") -end - task :mutate do system("bin/mutant run") end diff --git a/devenv.lock b/devenv.lock index 867955b..66f8095 100644 --- a/devenv.lock +++ b/devenv.lock @@ -173,7 +173,8 @@ "devenv": "devenv", "git-hooks": "git-hooks", "nixpkgs": "nixpkgs", - "nixpkgs-ruby": "nixpkgs-ruby" + "nixpkgs-ruby": "nixpkgs-ruby", + "treefmt-nix": "treefmt-nix" } }, "systems": { @@ -190,6 +191,26 @@ "repo": "default", "type": "github" } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1780220602, + "narHash": "sha256-eynAfOmbmxJnkp7YewvCEbShNnnYJ9gLLqkzsYtBPeM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "db947814a175b7ca6ded66e21383d938df01c227", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/devenv.nix b/devenv.nix index ed8ea7e..ed18882 100644 --- a/devenv.nix +++ b/devenv.nix @@ -18,12 +18,30 @@ ''; tasks = { - "app:format".exec = "bin/rake format"; + "app:format".exec = "treefmt"; "app:test".exec = "bin/rake test"; "app:mutate".exec = "bin/mutant run"; "app:check".exec = "bin/rake"; # default: test + mutate_since }; + # treefmt drives all formatters (Ruby via syntax_tree, SQL via sqlfluff). + treefmt.enable = true; + treefmt.config = { + projectRootFile = "devenv.nix"; + settings.formatter = { + ruby = { + command = "stree"; + options = [ "write" ]; + includes = [ "*.rb" ]; + }; + sql = { + command = "sqlfluff"; + options = [ "format" ]; + includes = [ "db/**/*.sql" ]; + }; + }; + }; + # Self-contained pg_regress run: spin up an ephemeral PostgreSQL with the # Nix server binaries, load the schema, run the regression schedule, then # tear it down. No Rakefile task, no gem, no env-var paths. @@ -81,12 +99,12 @@ claude.code.enable = true; claude.code.hooks.git-hooks-run.enable = false; - claude.code.hooks.format-ruby = { - name = "Format Ruby with syntax_tree"; + claude.code.hooks.format = { + name = "Format edited files with treefmt"; hookType = "PostToolUse"; matcher = "Write|Edit"; command = '' - jq -r '.tool_response.filePath // .tool_input.file_path' | { read -r f; case "$f" in *.rb) bin/stree write "$f" ;; esac; } 2>/dev/null || true + jq -r '.tool_response.filePath // .tool_input.file_path' | { read -r f; treefmt "$f"; } 2>/dev/null || true ''; }; } diff --git a/devenv.yaml b/devenv.yaml index 5a3d24b..fa85261 100644 --- a/devenv.yaml +++ b/devenv.yaml @@ -1,13 +1,18 @@ inputs: - nixpkgs: - url: github:cachix/devenv-nixpkgs/rolling git-hooks: url: github:cachix/git-hooks.nix inputs: nixpkgs: follows: nixpkgs + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling nixpkgs-ruby: url: github:bobvanderlinden/nixpkgs-ruby inputs: nixpkgs: follows: nixpkgs + treefmt-nix: + url: github:numtide/treefmt-nix + inputs: + nixpkgs: + follows: nixpkgs -- 2.51.2