-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can cargo fmt or rustfmt format a list of files please? #4485
Comments
I'm not entirely sure I understand what you are asking for.
Neither of these is git aware (nor any version control system) by design. There is the |
I think the core issue here is that |
I wasn’t aware that rustfmt could take a list of files. That’s great news -
will try that now.
…On Mon, 16 Nov 2020 at 11:52, Armin Ronacher ***@***.***> wrote:
I think the core issue here is that --skip-children is not actually
available on stable rustfmt. The current behavior is very confusing as
pointing it to src/main.rs will reformat the entire crate whereas src/
other.rs will typically reformat a single file.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4485 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGEJCBZADP44HXJCPCR6W3SQEG7FANCNFSM4SZQTCJA>
.
|
Oh yeah 5 times faster than black. That's much better. Right will close this - sorry all the talk around rustfmt was about stdin so I didn't realize it did a list of files. It's perfect - many thanks! |
@gilescope from my experience it doesn't really work. You can pass |
@mitsuhiko - I agree with you that the current default behavior is not ideal, and one of our planned changes with the as-of-yet-unreleased 2.0 was to invert that model (non-recursive by default with a If you think rustfmt can only format a single file then please open a new issue with steps to reproduce. Discussion of the skip_children behavior/stability is a bit off topic for the question asked here, and we'd want to utilize a new issue for tracking the potential stabilization of skip_children and/or any bugs |
cargo fmt -- ./a.rs # it also format b.rs rustfmt ./a.rs # only format a.rs |
And this is very annoying, we use a stable channel for everything, with the exception to the nightly fmt. So we cannot simply replace |
I'm a bit puzzled as to why folks are continuing to post increasingly orthogonal comments on an issue that's been closed for over a year. It also seems there's some general confusion/lack of awareness on the respective tools. The behavior has already been described above but I gather that it's still unclear or folks are simply not reading prior comments, so I'll attempt to explain one more time.
If you run
Will result in
Yes, it's true that Again, this is rustfmt behavior that makes no difference whether a human directly invokes
is false. If |
I bumped into this recently, and I found two ways to format a single file:
|
The other thing that cargo fmt does is to pass the correct edition defined in |
Pre-commit is widely used and one of the standard approaches is to call a tool with a list of modified files to process. It's pretty common across unix for commands to accept a list of files.
At the moment between
cargo fmt
andrustfmt
there doesn't seem to be a nice way to have pre-commit just run the formatter against just the files that have changed rather than all the files. We can do it by writing some python wrapper around rustfmt but it would be nice if we could just use it out of the box.The text was updated successfully, but these errors were encountered: