I think that there are two main considerations when making a change like this - how it affects irregular or new contributors and how it affects regular contributors - and what balance to strike between these when choosing a solution. I tend to lean toward making things easier for regular contributors at the expense of irregular contributors up until a point (or only when I think it is a particularly worthwhile change to make).
I’d propose that we have tidy check that code is correctly formatted and fail the CI if it is not. If that happens, then attempt to detect this (in some fashion similar to the log analyzer that is currently in use or an extension of this) and post a comment letting the contributor know that’s why there was a failure.
This comment would inform the contributor that they have two options - run x.py fmt locally which would use the correct rustfmt version and settings (which, as I understand it, would deal with a majority of the problems that people have found in requiring rustfmt on changes) and then push that; or mention @rustfmt apply which would add a new commit to their PR with that done for them.
This allows regular contributors to configure their local development environment to always run rustfmt and never need to worry about it - much like most contributors will already have set up with line lengths and trailing whitespace. If they aren’t comfortable with commits being added by bots unprompted to their PRs then that won’t happen - for these contributors, the workflow won’t change - they might need to modify their local environment slightly to apply formatting, but otherwise, everything is the same as it has been.
This also enables irregular contributors to deal with it themselves in a simple way - running one command and they’ve got the correct result; or have a bot deal with it for them.
By not having a bot automatically add formatting commits, this has a handful of advantages:
- Unrequested formatting commits won’t require PR authors pull and rebuild their own changes.
- Any review feedback won’t immediately be marked as outdated by these automatic commits.
- There will be a clear understanding and simple mental model for when commits are added - only when the bot is mentioned - not automatically, or only when it is detected as being required, etc.
- It avoids any confusion. In my opinion, I think it will be more confusing/frustrating for a new contributor or as someone unfamiliar with Git/GitHub when commits are being added automatically by bots than when CI is failing because of incorrect formatting.
This isn’t a be-all-end-all solution, but I think it is a decent compromise between approaches previously proposed. It could also be started straight away with the introduction of a tidy check and then the bot could be introduced later when it is ready or if there’s a lot of demand.
That said, in response to other solutions proposed above:
- I don’t think we should mix the responsibilities of
x.py subcommands by having x.py test also run formatting.
- However unlikely it is that it causes a problem, having code get changed automatically by bors after reviewing doesn’t sit well with me.