Format patches with rustfmt?


#1

Is it possible to use rustfmt to format patches (as in git format-patch)? If yes, that would be awesome because it could be used in a “pre-apply” git hook when working with a patch-mail workflow!


#2

Seems like if you can script a pre-apply hook, you can script patch application, running rustfmt on the modified tree, and re-computing the patch?

Disclaimer: I’m not really sold on the “all code must be formatted with rustfmt” approach, at least for my open or closed source projects. I did use rustfmt for a while to try and tame my style tendencies vs. community vetted standards, and I think it was very helpful in that regard. I’m still not 100% sold. FWIW I also live with my emacs/rust-mode config at about 98% satisfaction. For most of the high profile projects, the approach still seams to be “use local conventions”, and I think that is reasonable.


#3

Perhaps it’s helpful to look at it this way:
Most projects that involve more than 1 person (whether FOSS or not) that actually care about code style tend to have some kind of style guide. The question then becomes: wouldn’t it be useful if that style could be automatically enforced, rather than every developer having to apply it manually all the time? It would be the end of all style noncompliance issues in such projects while simultaneously allowing developers to write in their own preferred style, at the very least. Such flexibility and style enforcement is what tools like rustfmt and gofmt can do for you.

Now, if you don’t care about style enforcement, of course such tools will not sound very appetizing at all, but that’s like a master chef not needing a diamond saw in their kitchen :slight_smile:


#4

@jjpe lets have this debate on some other thread rather than hijack this one! I accept blame for my own bait, above. :slight_smile:


#5

I like it pretty much (having a common enforced style), but the story around huge whitespaces-only patches generated by rustfmt after mino edits (or sometimes just a new rustfmt version) isn’t totally solved IMHO.