`excludes` in `treefmt.toml` are ignored with `--stdin`
Describe the bug
Does treefmt.toml have no effect when using treefmt with --stdin?
To Reproduce
Steps to reproduce the behavior:
- configure zed & treefmt as above
- edit
foo/bar.nixin zed - save
Expected behavior
bar.nix file is not formatted
System information
system: nixos-unstable
treefmt: v2.3.1
zed: v0.188.3
Additional context
treefmt.toml
...
[formatter.nixfmt-rfc-style]
command = "nixfmt"
includes = ["*.nix"]
excludes = ["*/bar.nix"]
...
Zed
...
languages = {
Nix = {
...
formatter.external = {
command = "treefmt";
arguments = ["--stdin" "{buffer_path}"];
};
};
};
...
Does treefmt.toml have no effect when using
treefmtwith--stdin?
It does have an effect. If it did not, then foo/bar.nix wouldn't get formatted in your example (because treefmt wouldn't know how to format a .nix file.
You are correct that there's a bug here, though. I bet the issue is that we only use the excludes for walking the filesystem, and we also need to consider them when formatting via stdin.
~I'm pretty swamped right now. If someone hasn't fixed this by July, I'll take a look.~ This is on @brianmcgee's list.
Should be easy enough to fix, I've added it to my list for this week.
Looking at this a bit more closely, I think what you're seeing is this: https://github.com/numtide/treefmt/issues/573.
I believe we will respect excludes based on the extension, but because we currently don't preserve the original file path for the temp file we create from stdin, excludes = ["*/bar.nix"] will have no effect.
IIRC, ~#53~ #573 is about threading the filename down to the underlying formatter, which requires an extension to our formatter specification (#586). Fixing this wouldn't require support from the underlying formatters, right? It's entirely up to treefmt itself.
@brianmcgee quick ping here.
#53 relates to v1 and we don't have the equivalent in v2.
I think this can only be properly addressed when the discussions around #586 come to a conclusion.
Urg, sorry. There was a typo on my message. I still don't see how #586 is relevant here. This feels to me like something entirely up to treefmt's walker implementation(s).
Let's see if we can have a quick chat sometime this week. Feels like my smooth brain is just not grasping the nuance on this one.
Does treefmt.toml have no effect when using
treefmtwith--stdin?It does have an effect. If it did not, then
foo/bar.nixwouldn't get formatted in your example (because treefmt wouldn't know how to format a.nixfile.You are correct that there's a bug here, though. I bet the issue is that we only use the
excludesfor walking the filesystem, and we also need to consider them when formatting via stdin.~I'm pretty swamped right now. If someone hasn't fixed this by July, I'll take a look.~ This is on @brianmcgee's list.
Yeah, what seems to be getting considered for exclusions is the /some/tmp/path/12345.nix rather than actual_name.nix.
I completely forgot about this one. I need to test if it's still an issue in 2.4.0 as I did some fixes wrt stdin.