SlideShare a Scribd company logo
1 of 22
Download to read offline
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
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
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)
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
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)
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
similar conclusions by bbatsov:
MetaRedux post

More Related Content

Similar to Ruby formatters 2019

Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Muhammad Haseeb Shahid
 
Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Shaer Hassan
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & CucumberUdaya Kiran
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
Rubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with RubyRubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with RubyAkanksha Agrawal
 
Instruments ruby on rails
Instruments ruby on railsInstruments ruby on rails
Instruments ruby on railspmashchak
 
Debugging Rails 3 Applications
Debugging Rails 3 ApplicationsDebugging Rails 3 Applications
Debugging Rails 3 ApplicationsNathan Broadbent
 
The story of language development
The story of language developmentThe story of language development
The story of language developmentHiroshi SHIBATA
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overviewThomas Asikis
 
Ruby and Rails short motivation
Ruby and Rails short motivationRuby and Rails short motivation
Ruby and Rails short motivationjistr
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Railsmithunsasidharan
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done RightMariusz Nowak
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorialsunniboy
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystemGeison Goes
 

Similar to Ruby formatters 2019 (20)

Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
Ruby on Rails 3 Day BC
Ruby on Rails 3 Day BCRuby on Rails 3 Day BC
Ruby on Rails 3 Day BC
 
Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Rubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with RubyRubinius - Ruby Implemented with Ruby
Rubinius - Ruby Implemented with Ruby
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
Instruments ruby on rails
Instruments ruby on railsInstruments ruby on rails
Instruments ruby on rails
 
Debugging Rails 3 Applications
Debugging Rails 3 ApplicationsDebugging Rails 3 Applications
Debugging Rails 3 Applications
 
The story of language development
The story of language developmentThe story of language development
The story of language development
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
 
ruby pentest
ruby pentestruby pentest
ruby pentest
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
Ruby with cucmber
Ruby with cucmberRuby with cucmber
Ruby with cucmber
 
Ruby and Rails short motivation
Ruby and Rails short motivationRuby and Rails short motivation
Ruby and Rails short motivation
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystem
 

Recently uploaded

Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 

Recently uploaded (20)

Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 

Ruby formatters 2019

  • 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?
  • 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
  • 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)
  • 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
  • 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)
  • 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
  • 22. Thanks for listening similar conclusions by bbatsov: MetaRedux post