Ruby Style Guide 💻💎

What is Ruby Style Guide?

Ruby is the main language at Shopify. We are primarily a Ruby shop and we are probably one of the largest out there. Ruby is the go-to language for new web projects and scripting.

This Style Guide is the result of …


This content originally appeared on DEV Community and was authored by Edwin Nuñez

What is Ruby Style Guide?

Ruby is the main language at Shopify. We are primarily a Ruby shop and we are probably one of the largest out there. Ruby is the go-to language for new web projects and scripting.

This Style Guide is the result of over a decade of Ruby development at Shopify. Much of its content is based on Bozhidar Batsov's Ruby Style Guide, adapted to Shopify by many contributors.

— Installing Rubocop to Your Project

$ gem install rubocop

Now let’s create a program that can be linted better

name = "Karthik"
puts "Hello #{name}"

Now we save it and run Rubocop on it as shown:

$ rubocop rubocop_example.rb

rubocop spits out some errors as shown

Inspecting 1 file
C

Offenses:

rubocop_example.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
name = "Karthik"
^
rubocop_example.rb:1:8: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
name = "Karthik"
       ^^^^^^^^^

1 file inspected, 2 offenses detected, 2 offenses auto-correctable

- Create a .yml file in the root and paste this:

AllCops:
  NewCops: enable
  Exclude:
    - 'db/migrate/*.rb'
    - 'config/**/*.rb'
    - 'bin/*'
    - 'spec/rails_helper.rb'
    - 'lib/**/*.rb' #it should be fixed later
    - 'spec/lib/**/*.rb' #it should be fixed later
    - 'spec/requests/**/*.rb' #it should be fixed later
Metrics/BlockLength:
  Exclude:
    - 'Rakefile'
    - '**/*.rake'
    - 'spec/**/*.rb'
    - 'app/admin/**/*.rb'
    - 'db/**/*.rb'
    - 'db/migrate/*.rb'
    - 'config/*.rb'
Documentation:
  Include:
    - 'app/models/**/*.rb'
  Exclude:
    - 'app/models/ability.rb'
    - 'app/models/application_record.rb'
    - 'app/models/concerns/**'
    - 'app/models/filter_client.rb'
    - 'app/models/filter_warehouse.rb'
Metrics/MethodLength:
  Max: 12
Metrics/ClassLength:
  Max: 1000

That's all; Rubocop is now ready to work on your project! 🥳 🎉

Thank you for reading!đź“’

Guarapo Labs creates digital products that assist people in developing their ideas. Our staff has all of the necessary skills to work on your web and virtual reality game projects. Our commitment to educating our clients on how to provide the finest customer experience with their solutions is reflected in the high quality of our software.

Contact us edwin.nunez@guarapo.dev
Guarapo Labs
edwin-nunez - Overview


This content originally appeared on DEV Community and was authored by Edwin Nuñez


Print Share Comment Cite Upload Translate Updates
APA

Edwin Nuñez | Sciencx (2022-04-29T20:15:53+00:00) Ruby Style Guide 💻💎. Retrieved from https://www.scien.cx/2022/04/29/ruby-style-guide-%f0%9f%92%bb%f0%9f%92%8e/

MLA
" » Ruby Style Guide 💻💎." Edwin Nuñez | Sciencx - Friday April 29, 2022, https://www.scien.cx/2022/04/29/ruby-style-guide-%f0%9f%92%bb%f0%9f%92%8e/
HARVARD
Edwin Nuñez | Sciencx Friday April 29, 2022 » Ruby Style Guide 💻💎., viewed ,<https://www.scien.cx/2022/04/29/ruby-style-guide-%f0%9f%92%bb%f0%9f%92%8e/>
VANCOUVER
Edwin Nuñez | Sciencx - » Ruby Style Guide 💻💎. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/29/ruby-style-guide-%f0%9f%92%bb%f0%9f%92%8e/
CHICAGO
" » Ruby Style Guide 💻💎." Edwin Nuñez | Sciencx - Accessed . https://www.scien.cx/2022/04/29/ruby-style-guide-%f0%9f%92%bb%f0%9f%92%8e/
IEEE
" » Ruby Style Guide 💻💎." Edwin Nuñez | Sciencx [Online]. Available: https://www.scien.cx/2022/04/29/ruby-style-guide-%f0%9f%92%bb%f0%9f%92%8e/. [Accessed: ]
rf:citation
» Ruby Style Guide 💻💎 | Edwin Nuñez | Sciencx | https://www.scien.cx/2022/04/29/ruby-style-guide-%f0%9f%92%bb%f0%9f%92%8e/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.