Open tmuehlbacher opened 1 year ago
I have another use-case for this request.
I am looking into ways to integrate treefmt into Emacs for formatting on-save. For this it would be useful to be able to determine if one particular file can be formatted using treefmt. (The behavior of git ls-files
would work here as well except that a non-zero exit code would be convenient if the path is not covered by treefmt.toml
.)
That way I can enable calling treefmt on-save only if it's supported and otherwise maybe fall back to formatters that are configured globally by the editor (in my case by the Emacs format-all package).
@tmuehlbacher I have just implemented https://github.com/numtide/treefmt/commit/1b517c65024f9a80daaafe27064b7423b15cad82, which does a couple things.
By default, treefmt will log a warning for every path which does not match one or more formatters.
[!NOTE] Cached paths will not be emitted again until they have changed. So you'll see the warning the first time a file is added to the cache, and not on subsequent runs.
❯ nix fmt -- -c
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/.env
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/.envrc
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/.gitignore
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/LICENSE
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/.vitepress/config.mts
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/public/init.gif
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/public/just-use-go.png
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/public/logo.png
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/public/logo.svg
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/public/treefmt.gif
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/vhs/init.tape
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/docs/vhs/treefmt.tape
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/flake.lock
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/go.mod
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/go.sum
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/gomod2nix.toml
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/init.toml
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/elm/src/Main.elm
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/go/go.mod
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell-frontend/Main.hs
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell-frontend/Setup.hs
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell-frontend/haskell-frontend.cabal
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell/Foo.hs
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell/Main.hs
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell/Nested/Foo.hs
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell/Setup.hs
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell/haskell.cabal
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/haskell/treefmt.toml
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/html/scripts/.gitkeep
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/nixpkgs.toml
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/python/main.py
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/python/requirements.txt
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/python/virtualenv_proxy.py
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/ruby/bundler.rb
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/rust/Cargo.toml
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/rust/src/main.rs
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/shell/foo.sh
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/terraform/main.tf
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/terraform/two.tf
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/touch.toml
WARN format: no formatter for path: /home/brian/Development/com/github/numtide/treefmt/test/examples/treefmt.toml
traversed 99 files
emitted 99 files for processing
matched 58 files to formatters
formatted 0 files in 542.674671ms
You can change this behaviour using the -u
or --on-unmatched
flag, changing the log level of the message.
nix fmt -- -c -u debug
nix fmt -- -c -u info
nix fmt -- -c -u warn
nix fmt -- -c -u error
# this will exit the process with an error on the first path found to have no formatter
nix fmt -- -c -u fatal
In the long term I would like to add something like you describe above, but in the short term this might help.
Is your feature request related to a problem? Please describe.
I would like to be able to reliably tell that all of the files in my repo are covered by treefmt and also see files that are missing a formatter.
Describe the solution you'd like
An output similar to
git ls-files
, perhaps. I could be a command line switch to report the status, a message when using the--verbose
flag or separate CLI flags to report either one of the two groups.Describe alternatives you've considered
I ran
git ls-files
and reduced the output using a manually written regex based on my treefmt.toml file.