[For those who create portfolios] Reduce mistakes and make the code easier to read -Rubocop Airbnb-

What is Rubocop Airbnb?

It is a library that checks whether the written code complies with the coding standards. Rubocop is famous as a parsing tool, but since there are various settings, this time we will introduce rubocop-airbnb customized for the development site.

Introduction

install gem

Gemfile


 group :development, :test do
   gem 'rubocop-airbnb'
 end
 $ bundle install
File creation

Create new .rubocop.yml and .rubocop_airbnb.yml in the same directory as the Gemfile.

ruby:.rubocop.yml


inherit_from:
  - .rubocop_airbnb.yml

AllCops:
  Exclude:
  - 'bin/*'
  - 'config/**/*'
  - 'db/**/*'
  - 'spec/spec_helper.rb'

ruby:.rubocop_airbnb.yml


require:
   - rubocop-airbnb

If you get an error when calling, please be careful because you may have forgotten to add "." Or "_" in this file or you may have made a typo.

Run rubocop
$ rubocop --require rubocop-airbnb
Automatic correction method
$ rubocop --require rubocop-airbnb -a

Summary

It will be harder to fix later, so please try to introduce it before you start writing code.

reference

https://github.com/airbnb/ruby/tree/master/rubocop-airbnb

Recommended Posts

[For those who create portfolios] Reduce mistakes and make the code easier to read -Rubocop Airbnb-
[For those who create portfolios] How to use font-awesome-rails
[For those who create portfolios] How to use chart kick
[For those who create portfolios] How to omit character strings
[For those who create portfolios] How to use binding.pry with Docker
Create an Android app for those who don't want to play music on the speaker
[For those who create portfolios] Search function created with ransack
VS Code FAQ for those who want to escape Eclipse
Why was the code painful to read?