SlideShare a Scribd company logo
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
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?

Code formatter
It enforces a consistent style 

by parsing your code and 

re-printing it with its own rules
✴ Rubocop
✴ Rufo
✴ Prettifier
✴ Rubyfmt
RIP
✤ Ruby Script Beautifier (2008)
✤ eden (2011)
✤ ruby-beautify2 (fork: 01. 2018)
Formatters ruby
Parsers
Ripper to STD LIB - written in C so
faster



ruby-parse to CLI do gem parser:

production-ready written in pure
Ruby. It recognises as much or more
code than Ripper, Melbourne,
JRubyParser or ruby_parser, and is
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).
Ruby test
by rubocop
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
Ruby test
by Rufo
“uglifier” part
Rufo is fast
Less strict than prettier, but it seems that it formats less
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)
Fast per file - 175 ms

many files at once is not a case
Ruby test
by Rubyfmt



Rubyfmt problems
user_context&.role&.in? %w(Admin Company)
AddActivityService.new(candidate: candidate, **keywords).call
expect(email.body).to match 'His/her search can be shown'
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
Fast per file - 170 ms

many files at once is not a case
Ruby test
by Prettier



*designed by them : )
“uglifier” part
Prettier problems
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)
Rubyfmt - total time 30.s with some
errors during parsing
Formatter triggers
✓ On file save
✓ On code paste
✓ On demand
Sum up: How to live?
Use still linter
Chillout with code style wars
Try prettier formatter on demand/paste 

and report issues on GitHub
Thanks for listening

More Related Content

PPTX
Jaoo irony
KEY
IronRuby for the .NET Developer
PDF
IronRuby for the Rubyist
PPTX
IronRuby And The DLR
PPT
a quick Introduction to PyPy
ZIP
An Introduction to PyPy
PDF
PyPy
PDF
An introduction to the ruby ecosystem
Jaoo irony
IronRuby for the .NET Developer
IronRuby for the Rubyist
IronRuby And The DLR
a quick Introduction to PyPy
An Introduction to PyPy
PyPy
An introduction to the ruby ecosystem

What's hot (19)

PDF
Ruby and Rails short motivation
PDF
If programming languages were hot babes
PPTX
Extending Ruby using C++
PDF
Metaprogramming in Ruby
PPS
Ruby Introduction
PDF
Ola Bini J Ruby Power On The Jvm
PDF
Lets get started by Leif Gensert
PDF
Ruby an overall approach
PDF
FunScript: Why bother?
KEY
Using Aspects for Language Portability (SCAM 2010)
PDF
The Spoofax Language Workbench (SPLASH 2010)
PPT
Jug dynamic languages_in_jvm
KEY
Ruby On Rails Overview
KEY
Language Engineering in the Cloud
KEY
Wed Development on Rails
PPT
Building scalable and language independent java services using apache thrift
PPTX
Coffee scripts with rails
PPTX
IronRuby: Ruby on the .NET Platform
Ruby and Rails short motivation
If programming languages were hot babes
Extending Ruby using C++
Metaprogramming in Ruby
Ruby Introduction
Ola Bini J Ruby Power On The Jvm
Lets get started by Leif Gensert
Ruby an overall approach
FunScript: Why bother?
Using Aspects for Language Portability (SCAM 2010)
The Spoofax Language Workbench (SPLASH 2010)
Jug dynamic languages_in_jvm
Ruby On Rails Overview
Language Engineering in the Cloud
Wed Development on Rails
Building scalable and language independent java services using apache thrift
Coffee scripts with rails
IronRuby: Ruby on the .NET Platform
Ad

Similar to Ruby formatters (20)

PDF
Ruby formatters 2019
PPTX
Exploring Ruby on Rails and PostgreSQL
PDF
IDE, Terminal and SCM to work with Ruby on Rails
PPT
Rails Vs CakePHP
PDF
How DSL works on Ruby
PDF
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
KEY
Ruby On Rails
PPT
PDF
Code for Startup MVP (Ruby on Rails) Session 1
PPTX
Ruby on Rails : First Mile
DOCX
Page List & Sample Material (Repaired)
PPTX
Ruby and Security
PPT
Cucumber
PPT
Ruby On Rails
PDF
ruby pentest
PDF
The story of language development
ODP
Instruments ruby on rails
PPT
Ruby on Rails (RoR) as a back-end processor for Apex
PDF
Ruby Performance - The Last Mile - RubyConf India 2016
PDF
Intro to Crystal Programming Language
Ruby formatters 2019
Exploring Ruby on Rails and PostgreSQL
IDE, Terminal and SCM to work with Ruby on Rails
Rails Vs CakePHP
How DSL works on Ruby
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Ruby On Rails
Code for Startup MVP (Ruby on Rails) Session 1
Ruby on Rails : First Mile
Page List & Sample Material (Repaired)
Ruby and Security
Cucumber
Ruby On Rails
ruby pentest
The story of language development
Instruments ruby on rails
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby Performance - The Last Mile - RubyConf India 2016
Intro to Crystal Programming Language
Ad

More from Visuality (20)

PPTX
3 issues that made 30 test workers take 40 minutes
PPTX
Czego nie robić przy pisaniu testów
PDF
Introduction to Domain-Driven Design in Ruby on Rails
PDF
Active Record .includes - do you use it consciously?
PDF
Introduction to Event Storming
PDF
Jak programowanie może pomóc na co dzień?
PDF
SVG Overview - How To Draw, Use and Animate
PDF
How To Migrate a Rails App From a Dedicated Server Into Cloud Environment? - ...
PPTX
How to use AWS SES with Lambda 
in Ruby on Rails application - Michał Łęcicki
PPTX
What is NOT machine learning - Burak Aybar
PPTX
Do you really need to reload?
PDF
How to check valid email? Find using regex(p?)
PPTX
Fantastic stresses and where to find them
PDF
Fuzzy search in Ruby
PDF
Rfc process in visuality
PDF
GraphQL in Ruby on Rails - basics
PPTX
Consumer Driven Contracts
PDF
How do we use CircleCi in Laterallink?
PDF
React Native - Short introduction
PDF
Risk in project management
3 issues that made 30 test workers take 40 minutes
Czego nie robić przy pisaniu testów
Introduction to Domain-Driven Design in Ruby on Rails
Active Record .includes - do you use it consciously?
Introduction to Event Storming
Jak programowanie może pomóc na co dzień?
SVG Overview - How To Draw, Use and Animate
How To Migrate a Rails App From a Dedicated Server Into Cloud Environment? - ...
How to use AWS SES with Lambda 
in Ruby on Rails application - Michał Łęcicki
What is NOT machine learning - Burak Aybar
Do you really need to reload?
How to check valid email? Find using regex(p?)
Fantastic stresses and where to find them
Fuzzy search in Ruby
Rfc process in visuality
GraphQL in Ruby on Rails - basics
Consumer Driven Contracts
How do we use CircleCi in Laterallink?
React Native - Short introduction
Risk in project management

Recently uploaded (20)

PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Welding lecture in detail for understanding
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
composite construction of structures.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPT
Project quality management in manufacturing
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Construction Project Organization Group 2.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
PPT on Performance Review to get promotions
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Lecture Notes Electrical Wiring System Components
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Welding lecture in detail for understanding
R24 SURVEYING LAB MANUAL for civil enggi
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
composite construction of structures.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Project quality management in manufacturing
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Construction Project Organization Group 2.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Model Code of Practice - Construction Work - 21102022 .pdf
PPT on Performance Review to get promotions
bas. eng. economics group 4 presentation 1.pptx
Lecture Notes Electrical Wiring System Components

Ruby formatters

  • 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
  • 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?

  • 3. Code formatter It enforces a consistent style 
 by parsing your code and 
 re-printing it with its own rules
  • 4. ✴ Rubocop ✴ Rufo ✴ Prettifier ✴ Rubyfmt RIP ✤ Ruby Script Beautifier (2008) ✤ eden (2011) ✤ ruby-beautify2 (fork: 01. 2018) Formatters ruby
  • 5. Parsers Ripper to STD LIB - written in C so faster
 
 ruby-parse to CLI do gem parser:
 production-ready written in pure Ruby. It recognises as much or more code than Ripper, Melbourne, JRubyParser or ruby_parser, and is
  • 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) Fast per file - 175 ms
 many files at once is not a case
  • 14. Rubyfmt problems user_context&.role&.in? %w(Admin Company) AddActivityService.new(candidate: candidate, **keywords).call expect(email.body).to match 'His/her search can be shown'
  • 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 Fast per file - 170 ms
 many files at once is not a case
  • 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) Rubyfmt - total time 30.s with some errors during parsing
  • 20. Formatter triggers ✓ On file save ✓ On code paste ✓ On demand
  • 21. Sum up: How to live? Use still linter Chillout with code style wars Try prettier formatter on demand/paste 
 and report issues on GitHub