LoginSignup
2
2

More than 5 years have passed since last update.

RuboCop | Style/DotPosition

Posted at

RuboCop | Style/DotPosition

概要

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

複数行でメソッドを記述した場合に、ドットをどの行に記述するかをチェックする。
デフォルトはメソッド名と同じ行。

設定値一覧

設定対象 設定値 内容 デフォルト
EnforcedStyle leading メソッド名と同じ行にドットを記述する
EnforcedStyle trailing メソッド名の前の行にドットを記述する --

DotPosition

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

検証プログラム

preferred_methods.rb

p 'hIgE'
  .upcase

p 'hIgE'.
  downcase

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

.rubocop.yml

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

DotPosition:
  EnforcedStyle: leading
$ rubocop dot_position.rb
Inspecting 1 file
C

Offenses:

dot_position.rb:4:9: C: Place the . on the next line, together with the method name.
p 'hIgE'.
        ^

1 file inspected, 1 offense detected

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

.rubocop.yml

DotPosition:
  EnforcedStyle: trailing
$ rubocop dot_position.rb
Inspecting 1 file
C

Offenses:

dot_position.rb:2:3: C: Place the . on the previous line, together with the method call receiver.
  .upcase
  ^

1 file inspected, 1 offense detected
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