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

Many infinite loop issues when using --disable-uncorrectable flag #9922

Closed
thisismydesign opened this issue Jul 9, 2021 · 6 comments
Closed
Assignees
Labels

Comments

@thisismydesign
Copy link

Expected behavior

No errors or skip errors and continue running.

Actual behavior

Using rubocop -a --disable-uncorrectable a big project with no rubocop in the past results in many files running into infinite loops. Most often around Metrics/AbcSize and Metrics/MethodLength.

Using rubocop -a works.

Steps to reproduce the problem

I'll see if I can share code, but for now, I'm just curious to know if this is a known issue.

$ [bundle exec] rubocop -V
1.18.3
@jonas054
Copy link
Collaborator

Even if you can't share code, could you share the output of rubocop?

@thisismydesign
Copy link
Author

Sorry for the delay, just got approval to post the code. Here's a shorter file that reproduces the issue for me. Note, this happens for many files in fact.

bundle exec rubocop app/controllers/newsletter_recommendations_controller.rb -a --disable-uncorrectable

class NewsletterRecommendationsController < ApplicationController
  before_action :authenticate_user!

  def show
    # NOTE: admin logged-in-as not compatible (for now).
    raise "Unimplemented" if warden.authenticated?(scope: :admin_user)

    current_manager = current_user.manager

    raise ActiveRecord::RecordNotFound unless current_manager.present?

    newsletter_recommendation =
      NewsletterRecommendation.find_by(uuid: params[:uuid])

    raise ActiveRecord::RecordNotFound unless newsletter_recommendation

    employee =
      employee.find_for_company(
        newsletter_recommendation.employee_id,
        manager: current_manager,
        create_intro: true
      )

    intro = employee.introductions.where(manager_id: current_manager.id).last

    newsletter_recommendation.associate_introduction(intro)

    # NOTE: newsletter has a 1:1 relation between uuid and record rather than a uuid per result set
    rank = 0
    employee_id_with_tracking = "#{employee.id}-#{newsletter_recommendation.uuid}-#{rank}"

    respond_to do |format|
      format.html { redirect_to company_employee_path(employee_id_with_tracking) }
    end
  end
end

And here's the trace:

Inspecting 1 file
C

Offenses:

app/controllers/newsletter_recommendations_controller.rb:4:3: C: [Todo] Metrics/AbcSize: Assignment Branch Condition size for show is too high. [<7, 24, 3> 25.18/17]
  def show ...
  ^^^^^^^^
app/controllers/newsletter_recommendations_controller.rb:4:3: C: [Todo] Metrics/MethodLength: Method has too many lines. [19/10]
  def show ...
  ^^^^^^^^
app/controllers/newsletter_recommendations_controller.rb:4:12: C: [Corrected] Style/DoubleCopDisableDirective: More than one disable comment on one line.
  def show # rubocop:todo Metrics/AbcSize # rubocop:todo Metrics/MethodLength
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/newsletter_recommendations_controller.rb:6:11: C: [Corrected] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
    raise "Unimplemented" if warden.authenticated?(scope: :admin_user)
          ^^^^^^^^^^^^^^^

0 files inspected, 4 offenses detected, 4 offenses corrected
Infinite loop detected in /app/app/controllers/newsletter_recommendations_controller.rb and caused by Metrics/AbcSize, Metrics/MethodLength, Style/DoubleCopDisableDirective
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:299:in `check_for_infinite_loop'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:282:in `block in iterate_until_no_changes'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:281:in `loop'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:130:in `block in file_offenses'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:155:in `file_offense_cache'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:129:in `file_offenses'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:120:in `process_file'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:100:in `each'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:100:in `reduce'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:100:in `each_inspected_file'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:86:in `inspect_files'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/runner.rb:47:in `run'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli/command.rb:11:in `run'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli/environment.rb:18:in `run'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli.rb:65:in `run_command'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli.rb:72:in `execute_runners'
/usr/local/bundle/gems/rubocop-1.18.3/lib/rubocop/cli.rb:41:in `run'
/usr/local/bundle/gems/rubocop-1.18.3/exe/rubocop:12:in `block in <top (required)>'
/usr/local/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/usr/local/bundle/gems/rubocop-1.18.3/exe/rubocop:12:in `<top (required)>'
/usr/local/bundle/bin/rubocop:23:in `load'
/usr/local/bundle/bin/rubocop:23:in `<top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:463:in `exec'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:27:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:18:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'

Our ruboyop.yml

require:
  - rubocop-rspec
  - rubocop-rails
AllCops:
  TargetRubyVersion: 2.6
  NewCops: enable
  Exclude:
  - "db/schema.rb"
  - "vendor/**/*"
  - "search-tracking/db/schema.rb"

# Documentation not enforced
Style/Documentation:
  Enabled: false

@jonas054 jonas054 self-assigned this Jul 16, 2021
@jonas054 jonas054 added the bug label Jul 16, 2021
@jonas054
Copy link
Collaborator

Thanks for the report @thisismydesign. I'll try to fix it.

@koic koic closed this as completed in 49b3999 Jul 16, 2021
koic added a commit that referenced this issue Jul 16, 2021
…tive

[Fix #9922] Replace extra disable directives with comma
@thisismydesign
Copy link
Author

@jonas054 Thanks a lot for the quick fix! Could you ping this thread when the fix is released?

@jonas054
Copy link
Collaborator

@thisismydesign Ping! RuboCop 1.18.4 has been released.

@thisismydesign
Copy link
Author

Thanks @jonas054!

thearjunmdas pushed a commit to thearjunmdas/rubocop that referenced this issue Aug 20, 2021
Just removing cop names from disable directives is not a good
solution. It's bound to cause infinite loop errors when those cops try
to add the disable directives back. The natural solution is to put in
commas instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants