Skip to content

Commit

Permalink
Merge pull request rubocop#10672 from koic/fix_incorrect_autocorrect_…
Browse files Browse the repository at this point in the history
…for_layout_argument_alignment

[Fix rubocop#10671] Fix an incorrect autocorrect for `Layout/ArgumentAlignment`
  • Loading branch information
koic committed May 26, 2022
2 parents 858edfd + 20222a4 commit cdf0d4b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#10671](https://github.com/rubocop/rubocop/issues/10671): Fix an incorrect autocorrect for `EnforcedStyle: with_first_argument` of `Layout/ArgumentAlignment` and `EnforcedColonStyle: separator` of `Layout/HashAlignment`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/argument_alignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def enforce_hash_argument_with_separator?
return false unless hash_argument_config['Enabled']

RuboCop::Cop::Layout::HashAlignment::SEPARATOR_ALIGNMENT_STYLES.any? do |style|
hash_argument_config[style] == 'separator'
hash_argument_config[style]&.include?('separator')
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/rubocop/cli/autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,36 @@ def do_even_more_stuff
RUBY
end

it 'corrects when specifying `EnforcedStyle: with_first_argument` of `Layout/ArgumentAlignment` and ' \
'`EnforcedColonStyle: separator` of `Layout/HashAlignment` (`EnforcedColonStyle` is array)' do
create_file('example.rb', <<~RUBY)
attr_reader_with_default componentList: ['all'],
componentFileFilter: { 'all' => nil },
componentOption: { 'all' => { run_postinstall: true } },
descriptionList: {}
RUBY

create_file('.rubocop.yml', <<~YAML)
Layout/ArgumentAlignment:
EnforcedStyle: with_first_argument
Layout/HashAlignment:
AllowMultipleStyles: true
EnforcedColonStyle:
- separator
YAML

expect(
cli.run(['--autocorrect', '--only', 'Layout/ArgumentAlignment,Layout/HashAlignment'])
).to eq(0)
expect($stderr.string).to eq('')
expect(File.read('example.rb')).to eq(<<~RUBY)
attr_reader_with_default componentList: ['all'],
componentFileFilter: { 'all' => nil },
componentOption: { 'all' => { run_postinstall: true } },
descriptionList: {}
RUBY
end

it 'corrects when specifying `EnforcedStyle: with_first_argument` of `Layout/ArgumentAlignment` and ' \
'`EnforcedHashRocketStyle: separator` of `Layout/HashAlignment`' do
create_file('example.rb', <<~RUBY)
Expand Down

0 comments on commit cdf0d4b

Please sign in to comment.