[RUBY] [Rails] Gem Rubocop Static code analysis tool

What is Rubocop

A tool that statically analyzes whether or not it complies with Ruby's coding standards. It parses all the code written in the .rb file and outputs the indent, method name, etc. to the terminal.

Introduction method

Add the following to the Gemfile.

gem 'rubocop', require: false

Installation

$ bundle install

how to use

https://docs.rubocop.org/rubocop/1.7/usage/basic_usage.html

command

$ rubocop
#Analyze and output the result to the terminal
$ rubocop -a
 #or
$ rubocop --auto-correct
#Analyze and automatically correct

Configuration

Describe the settings in .rubocop.yml. (My settings)

.rubocop.yml


AllCops:
inherit_from: .rubocop_todo.yml
AllCops:
  Exclude:
    - bin/*
    - config/**/*
    - db/schema.rb
    - vendor/**/*
    - Gemfile
  NewCops: enable
Style/Documentation:
  Enabled: false
Style/EmptyMethod:
  Enabled: false
Style/FrozenStringLiteralComment:
  Enabled: false

Recommended Posts

[Rails] Gem Rubocop Static code analysis tool
Static code analysis with Checkstyle in Java + Gradle
[Rails] Organize your code neatly with gem active_decorator
[Rails 6] Rubocop warning list
Enhanced Java compilation errors with the static analysis tool ErrorProne