[Ruby] [For portfolio creators] Reduce mistakes and make code easier to read -Rubocop Airbnb-

less than 1 minute read

What is Rubocop Airbnb

It is a library that checks whether the written code complies with the coding standard. Rubocop is famous as a syntax analysis tool, but there are various settings, so 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
Create file

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 as you may forget to add “.” or “_” in this file or make a mistake in input.

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

Summary

The fix will get harder later, so be sure to try it before you start writing code.

reference

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