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

An error occurred while Style/IfUnlessModifier cop was inspecting a <Rails model with a scope> #9788

Closed
goulvench opened this issue May 8, 2021 · 1 comment

Comments

@goulvench
Copy link

My (working) Rails code seems to be causing the IfUnlessModifier cop to choke.

Actual behavior

$ rubocop --debug app/models/user.rb
An error occurred while Style/IfUnlessModifier cop was inspecting app/models/user.rb:28:60.
undefined method `last_argument' for #<RuboCop::AST::Node:0x00007f9fe625a890>
Did you mean?  last_line

/Users/goulven/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/rubocop-1.13.0/lib/rubocop/cop/style/if_unless_modifier.rb:71:in `autocorrect'
/Users/goulven/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/rubocop-1.13.0/lib/rubocop/cop/style/if_unless_modifier.rb:62:in `block in on_if'
/Users/goulven/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/rubocop-1.13.0/lib/rubocop/cop/base.rb:342:in `correct'
/Users/goulven/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/rubocop-1.13.0/lib/rubocop/cop/base.rb:127:in `add_offense'
/Users/goulven/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/rubocop-1.13.0/lib/rubocop/cop/style/if_unless_modifier.rb:61:in `on_if'

Steps to reproduce the problem

class User < ApplicationRecord
  scope :subscribed, -> { where(subscribed: true) }
  scope :unsubscribed, -> { where(subscribed: false) }
  scope :with_subscription_status, ->(subscription = nil) { (subscription == 'true' ? subscribed : unsubscribed) unless subscription.blank? }
end

RuboCop version

$ [bundle exec] rubocop -V
1.13.0 (using Parser 3.0.1.0, rubocop-ast 1.4.1, running on ruby 2.5.8 x86_64-darwin19)
@koic koic added the duplicate label May 8, 2021
@koic
Copy link
Member

koic commented May 8, 2021

This issue is a dup with #9729 and resolved by #9730. Please update to the latest RuboCop 1.14. Thank you.

@koic koic closed this as completed May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants