Rustfmt: list of files on commandline ignored

Created on 4 Aug 2018  路  5Comments  路  Source: rust-lang/rustfmt

I'm running rustfmt 0.9.0-nightly (d50e361 2018-08-01) from rustup. When I invoke rustfmt with a list of files, it formats all the files recursively from my current working directory, instead of just the files I listed.

Minimal repro case: https://github.com/tkilbourn/rustfmt-test
Run rustfmt src/main.rs. Observe src/other.rs is modified.

Most helpful comment

Ah, so this is WAI. I find this unintuitive, based on the usage message. Now that I know, the --skip-children flag makes sense, but I don't know if I'd have noticed it before. I know it would be a breaking change, but will --skip-children ever become the default? I imagine many users will be using it with cargo anyway.

All 5 comments

https://github.com/rust-lang-nursery/rustfmt#running
... This runs rustfmt on the given file, if the file includes out of line modules, then we reformat those too. So to run on a whole module or crate, you just need to run on the root file (usually mod.rs or lib.rs). ...

You can use --unstable-features --skip-children to prevent formatting child modules.

Ah, so this is WAI. I find this unintuitive, based on the usage message. Now that I know, the --skip-children flag makes sense, but I don't know if I'd have noticed it before. I know it would be a breaking change, but will --skip-children ever become the default? I imagine many users will be using it with cargo anyway.

@nrc Has there been any more consideration of this? Is there a plan for stabilizing --skip-children soon? Personally I also would find this much more intuitive as the default, since folks wanting to format their whole crate will likely prefer cargo fmt.

I'm planning on moving stabilise a bunch more flags and options once we get Rustfmt 1.0 out the door (i.e., post-edition). That will probably include this.

Thanks for the update!

Was this page helpful?
0 / 5 - 0 ratings