Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #9453] Fix an infinite loop error for `Layout/FirstParameterInde…
…ntation` Fixes #9453. This PR fixes the following infinite loop error for `Layout/FirstParameterIndentation` when `EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`. ```console % cat example.rb # frozen_string_literal: true RSpec.describe MyController, type: :controller do it 'abc' do expect(response).to redirect_to(path( obj1, id: obj2.id )) end end % cat .rubocop.yml AllCops: NewCops: enable Layout/ArgumentAlignment: EnforcedStyle: with_fixed_indentation % bundle exec rubocop -a --only Layout/ArgumentAlignment,Layout/FirstArgumentIndentation (snip) Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/9453/example.rb and caused by Layout/FirstArgumentIndentation -> Layout/ArgumentAlignment /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:304:in `check_for_infinite_loop' /Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes' ``` The following is the reason why an error occurs. First, `Layout/FirstArgumentIndentation` will auto-correct it. ```console % bundle exec rubocop -a --only Layout/FirstArgumentIndentation Inspecting 1 file C Offenses: example.rb:6:7: C: [Corrected] Layout/FirstArgumentIndentation: Indent the first argument one step more than path(. obj1, ^^^^ 1 file inspected, 1 offense detected, 1 offense corrected % cat example.rb # frozen_string_literal: true RSpec.describe MyController, type: :controller do it 'abc' do expect(response).to redirect_to(path( obj1, id: obj2.id )) end end ``` Next, `Layout/ArgumentAlignment` will auto-correct it. ```consloe % bundle exec rubocop -a --only Layout/ArgumentAlignment Inspecting 1 file C Offenses: example.rb:6:39: C: [Corrected] Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call. obj1, ^^^^ 1 file inspected, 1 offense detected, 1 offense corrected % cat example.rb # frozen_string_literal: true RSpec.describe MyController, type: :controller do it 'abc' do expect(response).to redirect_to(path( obj1, id: obj2.id )) end end ``` An infinite loop error occurs because it is corrected to the original code. This PR makes `Layout/FirstParameterIndentation` respect `Layout/ArgumentAlignment` when `EnforcedStyle: with_fixed_indentation` alternative configuration is specified for `Layout/ArgumentAlignment` to prevent the error.
- Loading branch information