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

0.83.0 broke this code with Style/IfUnlessModifier #7969

Closed
iGEL opened this issue May 13, 2020 · 1 comment
Closed

0.83.0 broke this code with Style/IfUnlessModifier #7969

iGEL opened this issue May 13, 2020 · 1 comment
Labels

Comments

@iGEL
Copy link
Contributor

iGEL commented May 13, 2020

Expected behavior

The code should be fine, as it is with 0.82.0:

Inspecting 1 file
.

1 file inspected, no offenses detected

Actual behavior

Offenses:

test.rb:6:17: C: [Corrected] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    _customer = if params[:customer_id]
                ^^
test.rb:6:18: C: [Corrected] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    _customer = (if params[:customer_id]
                 ^^
test.rb:6:72: C: [Corrected] Style/IfUnlessModifier: Modifier form of if makes the line too long.
    _customer = (CustomerCell.new(Customer.find(params[:customer_id])) if params[:customer_id])
                                                                       ^^

0 files inspected, 3 offenses detected, 3 offenses corrected
Infinite loop detected in /home/me/tmp/test.rb.
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:292:in `check_for_infinite_loop'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:275:in `block in iterate_until_no_changes'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `loop'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `iterate_until_no_changes'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:245:in `do_inspection_loop'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:124:in `block in file_offenses'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:148:in `file_offense_cache'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:122:in `file_offenses'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:113:in `process_file'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:92:in `block in each_inspected_file'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `reduce'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each_inspected_file'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:78:in `inspect_files'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/runner.rb:39:in `run'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/cli/command.rb:10:in `run'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/cli/environment.rb:17:in `run'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/cli.rb:65:in `run_command'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/cli.rb:72:in `execute_runners'
/home/me/.gem/gems/rubocop-0.83.0/lib/rubocop/cli.rb:41:in `run'
/home/me/.gem/gems/rubocop-0.83.0/exe/rubocop:13:in `block in <top (required)>'
/usr/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/me/.gem/gems/rubocop-0.83.0/exe/rubocop:12:in `<top (required)>'
/home/me/.gem/bin/rubocop:23:in `load'
/home/me/.gem/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

Create test.rb with this content:

class X
  def y
    _customer = if params[:customer_id]
      CustomerCell.new(Customer.find(params[:customer_id]))
    end
  end
end

Create .rubocop.yml with this content:

Layout/LineLength:
  Max: 85
Layout/EndAlignment:
  EnforcedStyleAlignWith: variable

Run rubocop -a test.rb

RuboCop version

Broken version:

$ rubocop -V
0.83.0 (using Parser 2.7.1.2, running on ruby 2.7.0 x86_64-linux-gnu)

Good version:

$ rubocop -V                   
0.82.0 (using Parser 2.7.1.2, running on ruby 2.7.0 x86_64-linux-gnu)

Possibly related change

I haven't checked, but I assume this change could have broken this: #7872

@dmytro-savochkin
Copy link

This should be closed due to #8435.

@koic koic closed this as completed Aug 3, 2020
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