1. prettier-ruby?
ruby formatters overview
"Good programmers" are those
who aleady have learned a set of rules that
ensures good style; (…)
The Elements of Programming Style 1974
Piotr
Wasiak
V 2019
2. Ruby programming style history
At the beginning there was chaos
We got some ruby styling guides
CodeReview focused sometimes more on style than the
logic
We got linters (PR services, overcommit, text-editor plugins)
Should we now follow e.g. JS world
with using automatic formatters?
6. Rubocop
heavy, but very good advanced configuration
parameters to use as formatter:
-a --auto-correct Auto-correct offenses.
--safe-auto-correct Run auto-correct only when it's safe.
-x, --fix-layout
Run only layout cops, with auto-correct on.
(currently 81 cops)
--only-guide-cops
Run only cops for rules that link to a style
guide.
--only [COP1,COP2,...] Run only the given cop(s).
8. RuFo
Not a simple find and replace one, very fast
Was implemented in a similar fashion to Crystal's
formatter.
Started 2 years ago, but currently is getting less updates
/ issues than prettier
There are some problems with chained heredocs, (…)
config options: trailing_commas, parens_in_def
11. Rufo is fast
Less strict than prettier, but it seems that it formats less
12. Rubyfmt
Fast, integrated with shell (no ruby gem)
Project development started 5 months ago
no config options.
No max chars/line, removes additional enters
Broke on some files (also especially @ rspec specs)
15. Prettier-ruby
Fast and opinionated in many languages as plugin to
text editors
Ruby plugin development started 7 months ago
config options:
printWidth, tabWidth, addTrailingCommas,
inlineConditionals, inlineLoops, preferHashLabels,
preferSingleQuotes
19. Speed
command User time
System
time
Total time
rufo ruby.rb 0.14s 0.05s 0.202s
./node_modules/.bin/
prettier
0.38s 0.08s 0.462s
Rubocop -a 1.09s 0.25s 1.349s
command User time
System
time
Total time
rufo **/*.rb 1.16s 0.20s 1.379s
Rubocop -a 3.18s 0.41s 3.635s
Rubocop -a —cache
false
14.34s 0.64s 15.174s
./node_modules/.bin/
prettier
36.23s 13.51s 51.606s
Format rails api project LOC: 2644 Format 1 file (ruby test)