Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop detected: Layout/ArgumentAlignment, Layout/ClosingParenthesisIndentation -> Layout/ClosingParenthesisIndentation, Layout/FirstArgumentIndentation #9453

Closed
jdufresne opened this issue Jan 29, 2021 · 0 comments · Fixed by #9486

Comments

@jdufresne
Copy link
Contributor

$ bundle exec rubocop -V
1.9.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-linux)

Config

AllCops:
  NewCops: enable

Layout/ArgumentAlignment:
  EnforcedStyle: with_fixed_indentation

Input

# 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
$ bundle exec rubocop -a blah.rb
Inspecting 1 file
C

Offenses:

blah.rb:6:7: C: [Corrected] Layout/FirstArgumentIndentation: Indent the first argument one step more than path(.
      obj1,
      ^^^^
blah.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,
                                      ^^^^
blah.rb:8:5: C: [Corrected] Layout/ClosingParenthesisIndentation: Indent ) to column 36 (not 4)
    ))
    ^
blah.rb:8:37: C: [Corrected] Layout/ClosingParenthesisIndentation: Indent ) to column 4 (not 36)
                                    ))
                                    ^

0 files inspected, 4 offenses detected, 4 offenses corrected
Infinite loop detected in .../blah.rb and caused by Layout/ArgumentAlignment, Layout/ClosingParenthesisIndentation -> Layout/ClosingParenthesisIndentation, Layout/FirstArgumentIndentation
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:304:in `check_for_infinite_loop'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:286:in `loop'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:157:in `file_offense_cache'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:131:in `file_offenses'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:122:in `process_file'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:100:in `each'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:100:in `reduce'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:86:in `inspect_files'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/runner.rb:47:in `run'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli/command.rb:11:in `run'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli/environment.rb:18:in `run'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli.rb:65:in `run_command'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli.rb:72:in `execute_runners'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/lib/rubocop/cli.rb:41:in `run'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/exe/rubocop:13:in `block in <top (required)>'
/usr/share/ruby/benchmark.rb:308:in `realtime'
.../vendor/bundle/ruby/2.7.0/gems/rubocop-1.9.0/exe/rubocop:12:in `<top (required)>'
.../vendor/bundle/ruby/2.7.0/bin/rubocop:23:in `load'
.../vendor/bundle/ruby/2.7.0/bin/rubocop:23:in `<top (required)>'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/share/gems/gems/bundler-2.1.4/libexec/bundle:46:in `block in <top (required)>'
/usr/share/gems/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/share/gems/gems/bundler-2.1.4/libexec/bundle:34:in `<top (required)>'
/usr/bin/bundle:23:in `load'
/usr/bin/bundle:23:in `<main>'
koic added a commit to koic/rubocop that referenced this issue Feb 1, 2021
…terIndentation`

Fixes rubocop#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.
bbatsov pushed a commit that referenced this issue Feb 1, 2021
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants