10
8

More than 5 years have passed since last update.

RuboCop | Style/AlignParameters | EnforcedStyle

Posted at

RuboCop | Style/AlignParameters | EnforcedStyle

概要

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

設定値一覧

設定対象 設定値 内容 デフォルト
EnforcedStyle with_first_parameter 最初のパラメータに位置を合わせる
EnforcedStyle with_fixed_indentation メソッド呼び出しの行から1段階インデントする --

EnforcedStyle

with_first_parameter, with_fixed_indentation

の各値での rubocop 実行結果をまとめます。

検証プログラム

enforced_style.rb

def some_method(a, b)
  "#{a}-#{b}"
end

some_method('hoge',
            'hige')

some_method('hoge',
  'hige')

EnforcedStyle with_first_parameter(デフォルト) でチェックした場合

.rubocop.yml

AlignParameters:
  EnforcedStyle: with_first_parameter

enforced_style.rb の2つ目の例が警告対象になります

$ rubocop
Inspecting 1 file
C

Offenses:

enforced_style.rb:9:3: C: Align the parameters of a method call if they span more than one line.
  'hige')
  ^^^^^^

1 file inspected, 1 offense detected

EnforcedStyle with_fixed_indentation でチェックした場合

.rubocop.yml

AlignParameters:
  EnforcedStyle: with_fixed_indentation

enforced_style.rb の1つ目の例が警告対象になります

$ rubocop
Inspecting 1 file
C

Offenses:

enforced_style.rb:6:13: C: Align the parameters of a method call if they span more than one line.
            'hige')
            ^^^^^^

1 file inspected, 1 offense detected

補足

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

10
8
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
10
8