Assumed audience: Software developers; this is about an auto-formatting tool for an open source repository (though not limited to open source).
I was just investigating integrating dprint to auto-format the Markdown files in the repository for The Rust Programming Language book, because doing it manually is a pain in the neck. Setting it up is the easy bit: dprint init and you’re off to the races. The slightly trickier bit is: I don’t really want to require contributors to do that, and I also don’t want Carol or myself to have to think about doing it after the fact if we keep our current policy of not requiring formatting to match to merge changes.
What I actually want is for commits to be able to land and then immediately get auto-formatted, so contributors don’t have to think about it, and neither do maintainers. Auto-formatting is best when it just works and stays out of your way.
I knew the DefinitelyTyped repository — for third — party TypeScript type definitions — had a bot wired up to do just this, so I took a few minutes today and figured out exactly how. The TS team set up DefinitelyTyped to report dprint issues using their Danger configuration,1 and they have a merge bot which does the actual merges, so I had assumed it was wired up with one of those, presumably the merge bot.
They just have a very simple GitHub action which checks out the code, makes sure CI, uses the date to configure a cache key, runs dprint fmt on anything which has changed, and commits the change. The end. That’s the whole thing.
I am not yet committed to wiring this up on The Rust Programming Language, but I am an awful lot closer to doing it given the only thing I would need to wrangle is an email address for the commit. And I will probably do it on other projects going forward (the same thing would work with rustfmt or Prettier or Ruff!) since it makes it so much easier for contributors.
Notes
I might write up notes on Danger some other time; it’s a nice little bot ↩︎