[Ruby] Rubocop で Ruby のコーディングスタンダードをチェックする

memo.

[markdown]
> * [bbatsov/rubocop: A Ruby static code analyzer, based on the community Ruby style guide.](https://github.com/bbatsov/rubocop)
> * [ruby-style-guide/README.ja.md at japanese · fortissimo1997/ruby-style-guide](https://github.com/fortissimo1997/ruby-style-guide/blob/japanese/README.ja.md)

## インストール

“`prettyprinted
% gem install rubocop
“`

## つかいかた

このファイルをチェックします。

> * [tools/resize_to_fill.rb at master · DriftwoodJP/tools](https://github.com/DriftwoodJP/tools/blob/master/imagemagick/resize_to_fill.rb)

“`prettyprinted
% rubocop
Inspecting 1 file
C
Offenses:
resize_to_fill.rb:9:1: C: Extra blank line detected.
resize_to_fill.rb:14:17: C: Avoid using {…} for multi-line blocks.
src_images.each { |file|
^
1 file inspected, 2 offenses detected
“`

規約違反を自動修正します。

“`prettyprinted
% rubocop -a
Inspecting 1 file
C
Offenses:
resize_to_fill.rb:9:1: C: [Corrected] Extra blank line detected.
resize_to_fill.rb:14:17: C: [Corrected] Avoid using {…} for multi-line blocks.
src_images.each { |file|
^
1 file inspected, 2 offenses detected, 2 offenses corrected
“`

このようになりました。

> * [Rubocop · 5a25679 · DriftwoodJP/tools](https://github.com/DriftwoodJP/tools/commit/5a25679c2527127ed6d7cc35efab3937c83370ee)

## 補遺

> * [コーディング規約をチェックするRubocopとPHP_CodeSniffer – SideCI Blog – CIツール「SideCI」の継続的インテグレーションブログ](http://sideci.hatenablog.com/entry/2014/05/07/155235)

`rubocop –auto-gen-config`

> * [Rubocop and Rails: Getting started – Joan’s Work](http://joanswork.com/rubocop-rails-getting-started/)
> * [rubocop のしつけ方 – onk.ninja](http://blog.onk.ninja/2015/10/27/rubocop-getting-started)
[/markdown]