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 bug in rubocop 1.57.0 #12261

Closed
ydakuka opened this issue Oct 11, 2023 · 1 comment · Fixed by #12267
Closed

Infinite loop bug in rubocop 1.57.0 #12261

ydakuka opened this issue Oct 11, 2023 · 1 comment · Fixed by #12267
Labels

Comments

@ydakuka
Copy link

ydakuka commented Oct 11, 2023

Actual behavior

If I run rubocop with autocorrect option:

~/Work/project$ bin/rails_docker rubocop -A app/models/user.rb

I will receive the problem:

0 files inspected, 404 offenses detected, 398 offenses corrected
Infinite loop detected in /app/app/models/user.rb and caused by Layout/FirstArgumentIndentation, Layout/LineLength
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:318:in `block in iterate_until_no_changes'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:314:in `loop'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:163:in `file_offenses'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:154:in `process_file'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:134:in `each'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:134:in `reduce'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:120:in `inspect_files'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/runner.rb:73:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli/command.rb:11:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli/environment.rb:18:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli.rb:118:in `run_command'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli.rb:125:in `execute_runners'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli.rb:51:in `block in run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/lib/rubocop/cli.rb:43:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/exe/rubocop:19:in `block in <top (required)>'
/usr/local/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.57.0/exe/rubocop:19:in `<top (required)>'
/usr/local/bin/rubocop:23:in `load'
/usr/local/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

class User < ApplicationRecord
  scope :custom_search, lambda { |query|
    left_joins(:profile)
      .where(
        CUSTOM_SEARCH_COLUMNS.map do |column|
          "LOWER(#{column}) LIKE :query"
        end.join(' OR '),
        query: "%#{Page.clean_url(query)}%",
      )
  }
end

RuboCop version

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -V
1.57.0 (using Parser 3.2.2.4, rubocop-ast 1.29.0, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.19.0
  - rubocop-factory_bot 2.24.0
  - rubocop-performance 1.19.1
  - rubocop-rails 2.21.1
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.24.1
  - rubocop-thread_safety 0.5.1
@koic koic added the bug label Oct 11, 2023
@ccutrer
Copy link
Contributor

ccutrer commented Oct 11, 2023

Similar problematic file:

# frozen_string_literal: true

describe 'SomeClass' do
  context 'SomeContext' do
    it 'imports outcomes that belongs to root folders' do
      outcome_model(
        title: 'Root group outcome',
        outcome_group: Account.default.root_outcome_group,
        context: Account.default
      )

      # force the creation of root outcome group in the course
      @course.root_outcome_group

      expect do
        exec(outcome_id: get_outcome_id('Root group outcome'))
      end.to not_change(LearningOutcomeGroup, :count)
        .and(change(ContentTag, :count).by(1))
        .and change {
          @course.root_outcome_group.child_outcome_links.map { |link| link.content.title }
        }.from([]).to(['Root group outcome'])
    end
  end
end

Default rubocop config,

cody@P6C2THJ7GJ src % rubocop -V
1.57.0 (using Parser 3.2.2.4, rubocop-ast 1.29.0, running on ruby 3.1.3) [arm64-darwin21]

running rubocop -x -- test.rb, output is:

0 files inspected, 309 offenses detected, 304 offenses corrected
Infinite loop detected in /Users/cody/src/test.rb and caused by Layout/BlockAlignment, Layout/LineLength
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:318:in `block in iterate_until_no_changes'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:314:in `loop'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:163:in `file_offenses'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:154:in `process_file'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:134:in `each'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:134:in `reduce'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:120:in `inspect_files'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/runner.rb:73:in `run'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli.rb:118:in `run_command'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli.rb:125:in `execute_runners'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli.rb:51:in `block in run'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/lib/rubocop/cli.rb:43:in `run'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/exe/rubocop:19:in `block in <top (required)>'
/Users/cody/.rubies/ruby-3.1.3/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/Users/cody/.gem/ruby/3.1.3/gems/rubocop-1.57.0/exe/rubocop:19:in `<top (required)>'
/Users/cody/.gem/ruby/3.1.3/bin/rubocop:25:in `load'
/Users/cody/.gem/ruby/3.1.3/bin/rubocop:25:in `<main>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants