Ruby formatters

Visuality
VisualityVisuality
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
1 de 22

Recomendados

Jaoo ironyJaoo irony
Jaoo ironyNick Hodge
403 vistas21 diapositivas
IronRuby for the .NET DeveloperIronRuby for the .NET Developer
IronRuby for the .NET DeveloperCory Foy
1.1K vistas69 diapositivas
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the RubyistWill Green
1K vistas34 diapositivas
IronRuby And The DLRIronRuby And The DLR
IronRuby And The DLRAndre John Cruz
498 vistas14 diapositivas
a quick Introduction to PyPya quick Introduction to PyPy
a quick Introduction to PyPyKai Aras
3K vistas52 diapositivas
An Introduction to PyPyAn Introduction to PyPy
An Introduction to PyPyMichael Hudson-Doyle
6.4K vistas23 diapositivas

Más contenido relacionado

La actualidad más candente

Ruby and Rails short motivationRuby and Rails short motivation
Ruby and Rails short motivationjistr
592 vistas42 diapositivas
Workin' on the Rails RoadWorkin' on the Rails Road
Workin' on the Rails RoadVishnu Gopal
1.5K vistas71 diapositivas
Extending Ruby using C++Extending Ruby using C++
Extending Ruby using C++Tristan Penman
454 vistas24 diapositivas
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Rubyjonromero
443 vistas10 diapositivas

La actualidad más candente(20)

An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystem
Geison Goes1.8K vistas
Workin' on the Rails RoadWorkin' on the Rails Road
Workin' on the Rails Road
Vishnu Gopal1.5K vistas
Extending Ruby using C++Extending Ruby using C++
Extending Ruby using C++
Tristan Penman454 vistas
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
jonromero443 vistas
Ruby IntroductionRuby Introduction
Ruby Introduction
Prabu D519 vistas
Lets get started by Leif GensertLets get started by Leif Gensert
Lets get started by Leif Gensert
Rails Girls MUC903 vistas
Intro dotnetIntro dotnet
Intro dotnet
OpenSource Technologies Pvt. Ltd.969 vistas
Ruby an overall approachRuby an overall approach
Ruby an overall approach
Felipe Schmitt1.3K vistas
FunScript: Why bother?FunScript: Why bother?
FunScript: Why bother?
Alfonso Garcia-Caro7.4K vistas
Jug dynamic languages_in_jvmJug dynamic languages_in_jvm
Jug dynamic languages_in_jvm
Dmitry Buzdin514 vistas
Ruby On Rails OverviewRuby On Rails Overview
Ruby On Rails Overview
jonkinney4.7K vistas
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloud
lennartkats833 vistas
Wed Development on RailsWed Development on Rails
Wed Development on Rails
James Gray1.3K vistas
Coffee scripts with railsCoffee scripts with rails
Coffee scripts with rails
Devilal Dheer429 vistas

Similar a Ruby formatters

Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHPGautam Rege
5.3K vistas27 diapositivas
How DSL works on RubyHow DSL works on Ruby
How DSL works on RubyHiroshi SHIBATA
5.1K vistas64 diapositivas

Similar a Ruby formatters(20)

Ruby formatters 2019Ruby formatters 2019
Ruby formatters 2019
Poznań Ruby User Group24 vistas
Rails Vs CakePHPRails Vs CakePHP
Rails Vs CakePHP
Gautam Rege5.3K vistas
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
Hiroshi SHIBATA5.1K vistas
Ruby On RailsRuby On Rails
Ruby On Rails
Eric Berry3.6K vistas
Ruby on Rails 3 Day BCRuby on Rails 3 Day BC
Ruby on Rails 3 Day BC
Northwest Independent Ruby Development428 vistas
Ruby on Rails : First MileRuby on Rails : First Mile
Ruby on Rails : First Mile
Gourab Mitra982 vistas
Page List & Sample Material (Repaired)Page List & Sample Material (Repaired)
Page List & Sample Material (Repaired)
Muhammad Haseeb Shahid111 vistas
Ruby and SecurityRuby and Security
Ruby and Security
Carl Sampson, CSSLP3.3K vistas
CucumberCucumber
Cucumber
Nagaraddi SS233 vistas
Ruby On RailsRuby On Rails
Ruby On Rails
Gautam Rege4.6K vistas
ruby pentestruby pentest
ruby pentest
testgmailnormal612 vistas
The story of language developmentThe story of language development
The story of language development
Hiroshi SHIBATA11K vistas
Instruments ruby on railsInstruments ruby on rails
Instruments ruby on rails
pmashchak1.3K vistas

Último(20)

Codes and Conventions.pptxCodes and Conventions.pptx
Codes and Conventions.pptx
IsabellaGraceAnkers6 vistas
Saikat Chakraborty Java Oracle Certificate.pdfSaikat Chakraborty Java Oracle Certificate.pdf
Saikat Chakraborty Java Oracle Certificate.pdf
SaikatChakraborty78714811 vistas
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptx
Dr.Shweta12 vistas
Solar PVSolar PV
Solar PV
Iwiss Tools Co.,Ltd11 vistas
Wire RopeWire Rope
Wire Rope
Iwiss Tools Co.,Ltd8 vistas
IEC 61850 Technical Overview.pdfIEC 61850 Technical Overview.pdf
IEC 61850 Technical Overview.pdf
ssusereeea975 vistas
Deutsch CrimpingDeutsch Crimping
Deutsch Crimping
Iwiss Tools Co.,Ltd15 vistas
String.pptxString.pptx
String.pptx
Ananthi Palanisamy47 vistas
Paper 3.pdfPaper 3.pdf
Paper 3.pdf
Javad Kadkhodapour6 vistas
Pointers.pptxPointers.pptx
Pointers.pptx
Ananthi Palanisamy62 vistas
SWM L15-L28_drhasan (Part 2).pdfSWM L15-L28_drhasan (Part 2).pdf
SWM L15-L28_drhasan (Part 2).pdf
MahmudHasan74787028 vistas
LFA-NPG-Paper.pdfLFA-NPG-Paper.pdf
LFA-NPG-Paper.pdf
harinsrikanth40 vistas
What is Unit TestingWhat is Unit Testing
What is Unit Testing
Sadaaki Emura21 vistas
Sanitary Landfill- SWM.pptxSanitary Landfill- SWM.pptx
Sanitary Landfill- SWM.pptx
Vinod Nejkar5 vistas

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