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

False positive for Performance/BindCall #464

Closed
TastyPi opened this issue Sep 9, 2024 · 3 comments
Closed

False positive for Performance/BindCall #464

TastyPi opened this issue Sep 9, 2024 · 3 comments

Comments

@TastyPi
Copy link

TastyPi commented Sep 9, 2024

def example(&block)
  block.bind(self).call { puts "inner block" }
end

gets turned into

def example(&block)
  block.bind_call(self) { puts "inner block" }
end

but block doesn't have a bind_call method because it isn't a method, so this throws NoMethodError: undefined method bind_call' for an instance of Proc`


Expected behavior

Should ignore bind methods called on block parameters.

Actual behavior

Generates invalid code (see above)

Steps to reproduce the problem

See example above

RuboCop version

1.65.1 (using Parser 3.3.5.0, rubocop-ast 1.32.3, running on ruby 3.3.4) +server [x86_64-linux]
  - rubocop-capybara 2.21.0
  - rubocop-i18n 1.14.5
  - rubocop-minitest 0.36.0
  - rubocop-performance 1.21.1
  - rubocop-rails 2.25.1
  - rubocop-rake 0.6.0
  - rubocop-thread_safety 0.5.1
@koic koic added the bug Something isn't working label Sep 11, 2024
@Earlopain
Copy link
Contributor

Proc also doesn't respond to bind so isn't the code broken to begin with? This results in NoMethodError before and after correction.

@TastyPi
Copy link
Author

TastyPi commented Sep 13, 2024

Oh, I did not realise I was getting this functionality from a gem, nevermind https://github.com/thoughtbot/shoulda-context/blob/main/lib/shoulda/context/proc_extensions.rb

@TastyPi TastyPi closed this as completed Sep 13, 2024
@koic koic removed the bug Something isn't working label Sep 13, 2024
@Earlopain
Copy link
Contributor

Thanks for the context, that's a blast from the past. Apparently rails removed that in 4.1. Also see
rails/rails#5552. Maybe you can also just use instance_exec thoughtbot/shoulda-context@e80456b? Just a sidenote, the GC caveat doesn't apply anymore today, symbols are garbage collected.

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

No branches or pull requests

3 participants