Skip to content

EnforcedLastArgumentHashStyle: always_ignore を設定すると Layout/AlignHash がインデントしてくれない #56

@znz

Description

@znz

メソッドの引数のハッシュのインデントがなぜか変化しないので、設定なしの環境で試してみたところ、 Layout/AlignHash で auto correct されるとわかったので、設定を確認したところ、 EnforcedLastArgumentHashStyle: always_ignore だけ設定していたのですが、なぜかインデントに影響していました。

https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/AlignHash の説明をみても、最後のハッシュを {} でくくるかどうかだけに影響しているように見えるのですが、インデントの変更はしてほしい場合はどうすればいいのでしょうか?

% cat .rubocop.yml
Layout/AlignHash:
  EnforcedLastArgumentHashStyle: always_ignore
% cat create.rb
# frozen_string_literal: true

FactoryBot.create :user, name: 'name',
  email: '[email protected]'
% rubocop -a create.rb
Inspecting 1 file
.

1 file inspected, no offenses detected
%  rm .rubocop.yml
% rubocop -a create.rb
Inspecting 1 file
C

Offenses:

create.rb:4:3: C: [Corrected] Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
  email: '[email protected]'
  ^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
% cat create.rb
# frozen_string_literal: true

FactoryBot.create :user, name: 'name',
                         email: '[email protected]'
% rubocop -V
0.72.0 (using Parser 2.6.3.0, running on ruby 2.6.3 x86_64-darwin18)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions