Infinite loop when fixing standard(Layout/EndAlignment)
henrahmagix opened this issue · 7 comments
~This seems unique in that it's not directly an issue on RuboCop's autocorrect for the Layout cops 🤔 ~ Edit: see later comments =)
# infinite.rb
class MyClass
def thing
@thing ||= class << Object.new
puts "self: #{self}"
end
end
end
MyClass.new.thing
First, just to confirm the code is fine:
$ ruby infinite.rb
self: #<Class:#<Object:0x0000000100bdeb78>>
Expected
Edit: see later comments; click to see original
Rubocop detects and corrects fine:
$ bundle exec rubocop -a infinite.rb
Inspecting 1 file
W
Offenses:
infinite.rb:4:7: C: [Corrected] Layout/IndentationWidth: Use 2 (not -9) spaces for indentation.
puts "self: #{self}"
^^^^^^^^^
infinite.rb:5:5: W: [Corrected] Layout/EndAlignment: end at 5, 4 is not aligned with class at 3, 15.
end
^^^
1 file inspected, 2 offenses detected, 2 offenses corrected
# infinite.rb, corrected
class MyClass
def thing
@thing ||= class << Object.new
puts "self: #{self}"
end
end
end
MyClass.new.thing
Actual
Now for Standard: I've reverted the file back to what it was
$ standardrb infinite.rb
standard: Use Ruby Standard Style (https://github.com/standardrb/standard)
infinite.rb:4:7: Layout/IndentationWidth: Use 2 (not -9) spaces for indentation.
infinite.rb:5:5: Layout/EndAlignment: `end` at 5, 4 is not aligned with `class` at 3, 15.
standard: Run `standardrb --fix` to fix up to 2 problems.
$ standardrb --fix infinite.rb
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:332:in `check_for_infinite_loop': Infinite loop detected in /me/standardrb-infinite-loop-test/infinite.rb and caused by Layout/EndAlignment (RuboCop::Runner::InfiniteCorrectionLoop)
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:315:in `block in iterate_until_no_changes'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:314:in `loop'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:283:in `do_inspection_loop'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:164:in `block in file_offenses'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:189:in `file_offense_cache'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:163:in `file_offenses'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:154:in `process_file'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:134:in `each'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:134:in `reduce'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:134:in `each_inspected_file'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:120:in `inspect_files'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/runner.rb:73:in `run'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.57.2/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/standard-1.32.1/lib/standard/runners/rubocop.rb:15:in `call'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/standard-1.32.1/lib/standard/cli.rb:14:in `run'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/standard-1.32.1/exe/standardrb:7:in `<top (required)>'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/standardrb:25:in `load'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/standardrb:25:in `<main>'
Thanks for the library =)
Just realised I'm behind the latest release, so I updated to 1.33.0, which pulled down rubocop 1.59.0 (vs 1.57.2 above), and I got the same error with what looks to be the same stack trace:
$ standardrb --fix infinite.rb
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:332:in `check_for_infinite_loop': Infinite loop detected in /me/standardrb-infinite-loop-test/infinite.rb and caused by Layout/EndAlignment (RuboCop::Runner::InfiniteCorrectionLoop)
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:315:in `block in iterate_until_no_changes'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `loop'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:163:in `file_offenses'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:154:in `process_file'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `reduce'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:120:in `inspect_files'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:73:in `run'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/standard-1.33.0/lib/standard/runners/rubocop.rb:15:in `call'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/standard-1.33.0/lib/standard/cli.rb:14:in `run'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/standard-1.33.0/exe/standardrb:7:in `<top (required)>'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/standardrb:25:in `load'
from /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/standardrb:25:in `<main>'
When you tested rubocop versus standard, did you ensure the rubocop configuration of the rule exactly matched the configuration standard ships with? Since Standard hands off to RuboCop and then does nothing, we've never had an infinite loop bug before that wasn't itself a bug in rubocop
Ah, of course! Thanks for reminding me – so I've rerun rubocop and pointed it to the config file in standard, and yeah, it errs the same =)
$ bundle exec rubocop -a --config /me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/standard-1.33.0/config/ruby-3.2.yml -- infinite.rb
Inspecting 1 file
W
Offenses:
infinite.rb:4:7: C: [Corrected] Layout/IndentationWidth: Use 2 (not -9) spaces for indentation.
puts "self: #{self}"
^^^^^^^^^
infinite.rb:5:5: W: [Corrected] Layout/EndAlignment: end at 5, 4 is not aligned with class at 3, 15.
end
^^^
0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /me/standardrb-infinite-loop-test/infinite.rb and caused by Layout/EndAlignment
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:332:in `check_for_infinite_loop'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:315:in `block in iterate_until_no_changes'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `loop'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:163:in `file_offenses'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:154:in `process_file'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `reduce'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:120:in `inspect_files'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/runner.rb:73:in `run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/command.rb:11:in `run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli/environment.rb:18:in `run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli.rb:118:in `run_command'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli.rb:125:in `execute_runners'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli.rb:51:in `block in run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/lib/rubocop/cli.rb:43:in `run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/exe/rubocop:19:in `block in <top (required)>'
/me/.rbenv/versions/3.2.2/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/rubocop-1.59.0/exe/rubocop:19:in `<top (required)>'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/rubocop:25:in `load'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/rubocop:25:in `<top (required)>'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:58:in `load'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:58:in `kernel_load'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/cli/exec.rb:23:in `run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/cli.rb:492:in `exec'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/cli.rb:34:in `dispatch'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/cli.rb:28:in `start'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/exe/bundle:37:in `block in <top (required)>'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/gems/bundler-2.4.19/exe/bundle:29:in `<top (required)>'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/bundle:25:in `load'
/me/.rbenv/versions/3.2.2/gemsets/standardrb-infinite-loop-test/bin/bundle:25:in `<main>'
Here's the file at the end of it:
# infinite.rb
class MyClass
def thing
@thing ||= class << Object.new
puts "self: #{self}"
end
end
end
MyClass.new.thing
have edited the title and description to reflect this =)
Well, that's a relief. I'd recommend filing this against the http://github.com/rubocop/rubocop repo, then. cc/ @koic
I've opened rubocop/rubocop#12580 to fix this issue. Note, since Standard gem is configured with EnforcedStyleAlignWith: variable
, it would be expected behavior that no offenses are registered:
Thanks so much both!