22nd April, 2020 Output.

Overview

RuboCop is a Ruby source code analysis tool that automatically checks if your code conforms to the Ruby style guide from the Ruby community (English/Japanese), or other style guides (such as MeowCop, which our company provides). It focuses on enforcing Rails best practices and coding conventions.

Advantages

  1. It indicates the project coding rules.

  2. By using Rubocop to keep the codes clean, you’ll have fewer mistakes and it leads to effective review.

Installation

Just install the rubocop gem

gem install rubocop

or if you use bundler put this in your Gemfile

gem 'rubocop', require: false

How to write .rubocop.yml file

By placing the configuration file .rubocop.yml in the root directory of the project, RuboCop will read this automatically. Or it can also specify a yml file in any location as a configuration file by -c option.

Below are the representative codes in .rubocop.yml file.

Specify the file to exclude from RuboCop

Use Exclude: to exclude files like (db/schema.rb) which is automatically generated by Rails,

or gem placed under vendor/bundle from RuboCop.

For example, use the following to exclude the db/schema.rb file from RuboCop.

AllCops:

  Exclude:

    - db/schema.rb

Enabling/Disabling Cop (Enabled: false/true)

When you feel a certain cop isn’t suitable for the project, you can disable it individually.

Style/TrailingComma:

 Enabled: false

Reference

RuboCop

Sider

Previous
Previous

MY TAKE ON OWASP AND RAILS GOAT

Next
Next

20th April - Security