Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 29, 2022 08:15 pm GMT

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 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 lets 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 laterMetrics/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: 12Metrics/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 [email protected]
Guarapo Labs
edwin-nunez - Overview


Original Link: https://dev.to/edwinnv/how-install-ruby-style-guide-2296

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To