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 in /Users/robert/gh/lab42/tmp/example.rb and caused by Layout/IndentationConsistency -> Layout/IndentationWidth #10396

Closed
RobertDober opened this issue Feb 3, 2022 · 3 comments · Fixed by #10617
Labels

Comments

@RobertDober
Copy link

Expected behavior

Autocorect

Actual behavior

Crash

Steps to reproduce the problem

rubocop --debug example.rb -A                                                                                                                                     [9:23:54]
For /Users/robert/gh/lab42/tmp: configuration from /Users/robert/gh/lab42/tmp/.rubocop.yml
Default configuration from /Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/config/default.yml
Inspecting 1 file
Scanning /Users/robert/gh/lab42/tmp/example.rb
C

Offenses:

example.rb:6:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not 16) spaces for indentation.
                  def color_value(color_spec)
  ^^^^^^^^^^^^^^^^
example.rb:6:5: C: [Corrected] Layout/IndentationConsistency: Inconsistent indentation detected.
    def color_value(color_spec) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /Users/robert/gh/lab42/tmp/example.rb and caused by Layout/IndentationConsistency -> Layout/IndentationWidth
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:298:in `check_for_infinite_loop'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:281:in `block in iterate_until_no_changes'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:280:in `loop'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:280:in `iterate_until_no_changes'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:249:in `do_inspection_loop'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:120:in `process_file'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:100:in `each'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:100:in `reduce'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/runner.rb:47:in `run'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:71:in `run_command'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:78:in `execute_runners'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cli.rb:47:in `run'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/exe/rubocop:12:in `block in <top (required)>'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/Users/robert/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/exe/rubocop:12:in `<top (required)>'
/Users/robert/.asdf/installs/ruby/3.1.0/bin/rubocop:25:in `load'
/Users/robert/.asdf/installs/ruby/3.1.0/bin/rubocop:25:in `<main>'

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

rubocop -V                                                                                                                                                        [9:27:10]
1.25.1 (using Parser 3.1.0.0, rubocop-ast 1.15.1, running on ruby 3.1.0 x86_64-darwin21)

resources.zip

@RobertDober
Copy link
Author

Oh here is the state of the partially corrected file when rubocop crashes

# frozen_string_literal: true

require_relative "tag_cloud/compiler"

module Lab42
  module TagCloud extend self
                  def color_value(color_spec)
                    Compiler.color_value(color_spec.to_s)
                  end
  end
end
#  SPDX-License-Identifier: Apache-2.0

@RobertDober
Copy link
Author

after some tinkering I found out that the extend self in the same line as module triggers this exception

@koic koic added the bug label Feb 3, 2022
@j-miyake
Copy link
Contributor

j-miyake commented May 7, 2022

I reproduced this problem disabling Style/TrailingBodyOnModule.

The code to reproduce.

module Foo extend Bar
  something
end

# Got this error:
# Infinite loop detected in /path/to/example.rb and caused by Layout/IndentationConsistency -> Layout/IndentationWidth

# Things following the module name doesn't have to be `extend`. This code causes the same error.
#
# module Foo bar
#   something
# end

The autocorrect works with no errors when Style/TrailingBodyOnModule is enabled.

module Foo
  extend Bar
  something
end

Should we fix Layout/IndentationConsistency not to align with the thing just next to the module name, or fix Layout/IndentationWidth to allow aligning with it?


There is the same problem with the class definition when Style/TrailingBodyOnClass is disabled.

class Foo bar
  something
end

j-miyake added a commit to j-miyake/rubocop that referenced this issue May 11, 2022
…leave module/class body unchanged to avoid infinite autocorrect loop with `Layout/IndentationConsistency` when the body trails after class/module definition
bbatsov pushed a commit that referenced this issue May 26, 2022
…odule/class body unchanged to avoid infinite autocorrect loop with `Layout/IndentationConsistency` when the body trails after class/module definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment