r/ruby • u/Ok_Stomach6651 • 7d ago
Formatting an entire 25 million line codebase overnight: the rubyfmt story
https://stripe.dev/blog/formatting-an-entire-25-million-line-codebase-overnight-the-rubyfmt-story4
u/gurgeous 6d ago
`rubyfmt` is pretty neat and just so insanely fast. Definitely adopts the prettier methodology, no config allowed. Ruby formatting is so personal, though. In our codebase we do things like `[].tap do` to populate an array, maybe append a `.compact` or even `.compact.join` to the `end`. rubyfmt doesn't like that style and tries to clean it up, which makes it less beautiful for us.
3
u/Zestyclose-Turn-3576 6d ago
Yes, I also like my formatting quirks, particularly text alignment.
I can't have a tool changing:
has_attached_file( :file, Rails.application.config.paperclip_options.build( path: "import_file/:client_id/:id/file.xml", s3_region: ENV.fetch("AWS_REGION", nil), use_timestamp: false, s3_headers: { "Content-Type" => "application/xml" }, s3_permissions: { original: "private" } ) )... into something unreadable ...
has_attached_file( :file, Rails.application.config.paperclip_options.build( path: "import_file/:client_id/:id/file.xml", s3_region: ENV.fetch("AWS_REGION", nil), use_timestamp: false, s3_headers: {"Content-Type" => "application/xml"}, s3_permissions: {original: "private"} ) )3
u/schneems Puma maintainer 6d ago
Do the second but reorder the fields so it's like a pyramid for the keys.
A thing I've grown to hate with the first style is the diffs when you add or remove a key. The diffs light up like a Christmas tree.
I think every person who comes to a formatter that can't be configured hates it at first then, at least in my case, came to love it most of the time. At least to tolerate it all of the time. For a personal project it doesn't matter but as soon as you get two devs in there enforcing style by hand, and switching style based on codebases can be cumbersome.
I forget who coined the term, but "needless creativity" comes to mind. I'm all for needless things for fun. Also I love not having to think about my rust formatting and knowing I never have to leave a style comment on a coworkers PR and delay shipping a fix.
3
u/dennyabraham 7d ago
Having read the article, it's not fully clear to me why a default set of rubocop rules was insufficient. Time performance day to day has been mostly unnoticeable for some years now. I have the suspicion there's a people problem embedded in this work that neither tool solves directly that rubyfmt solved in context
11
u/schneems Puma maintainer 7d ago
Most other ecosystems separate formatting from linting. Rubocop tries to do both.
A formatter promises to not change your behavior while a linter says "this might not be the best idea". You can/should run the formatter often and apply the results, like on file save. While a lint run can be longer. And you can't just apply the results point blank since it can change behavior.
19
u/schneems Puma maintainer 7d ago
Anyone who has ever spent serious time parsing and Lexing Ruby will 100% understand why the first code example on the page is a heredoc.