numtide / treefmt

one CLI to format your repo [maintainers=@zimbatm,@brianmcgee]
https://treefmt.com
MIT License
602 stars 37 forks source link

--fail-on-change should specify the file(s) that changed #380

Closed kjeremy closed 2 months ago

kjeremy commented 2 months ago

Is your feature request related to a problem? Please describe.

I would like --fail-on-change to tell me which files failed the check.

Describe the solution you'd like

Instead of saying treefmt: error: unexpected changes detected, --fail-on-change is enabled it should say something like:

treefmt: error: unexpected changes detected
  ./someproject/src/a.cpp
  ./nix/b.nix

Describe alternatives you've considered

Additional context

I am trying to run this in a CI pipeline where it would be useful to see where formatting is failing.

brianmcgee commented 2 months ago

If you pass -v or -vv it should log the offending file. I agree though, maybe that should be getting logged at warn or error level instead so it gets logged regardless of the verbosity level.

brianmcgee commented 2 months ago

381 addresses this:

❯ fmt --fail-on-change 
ERRO format: file has changed path=.github/dependabot.yml prev_size=133 prev_mod_time="2024-08-13 20:35:31 +0100 IST" current_size=128 current_mod_time="2024-08-13 20:37:09 +0100 IST"
ERRO format: file has changed path=.github/settings.yml prev_size=5765 prev_mod_time="2024-08-13 20:35:31 +0100 IST" current_size=5760 current_mod_time="2024-08-13 20:37:09 +0100 IST"
treefmt: error: unexpected changes detected, --fail-on-change is enabled