2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RuboCop | Style/EmptyLineBetweenDefs

Posted at

RuboCop | Style/EmptyLineBetweenDefs

概要

RuboCopの「Style/EmptyLineBetweenDefs」警告について。

メソッドの定義間に空白行を必要とするかどうかを設定し、チェックします。
デフォルトは空白行を必要としません。

設定値一覧

設定対象 設定値 内容 デフォルト
AllowAdjacentOneLineDefs false 無効
AllowAdjacentOneLineDefs true 有効 --

EmptyLineBetweenDefs

各設定値( false , true )での検証結果をまとめます。

検証プログラム

empty_line_between_defs.rb

def hoge
  'hoge'
end
def hige
  'hige'
end

実行結果 デフォルト の場合

.rubocop.yml

※明示的に設定しているが、デフォルト値なので何も設定しなくてもよい

EmptyLineBetweenDefs:
  AllowAdjacentOneLineDefs: false

メソッド間に空白行がありませんが、警告は出ません

$ rubocop empty_line_between_defs.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

実行結果 EmptyLineBetweenDefs を trailing に変更した場合

.rubocop.yml

EmptyLineBetweenDefs:
  AllowAdjacentOneLineDefs: true

メソッド間に空白行があるため、警告が発生しました

$rubocop empty_line_between_defs.rb  -a
Inspecting 1 file
C

Offenses:

empty_line_between_defs.rb:2:3: C: [Corrected] Prefer single-quoted strings when you don't need string interpolation or special symbols.
  "hoge"
  ^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

補足

この警告は rubocop -a で修正可能です。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?