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

Failing example for Naming/BlockForwarding and Lint/UselessAssignment #11313

Closed
kalsan opened this issue Dec 21, 2022 · 3 comments · Fixed by #11316
Closed

Failing example for Naming/BlockForwarding and Lint/UselessAssignment #11313

kalsan opened this issue Dec 21, 2022 · 3 comments · Fixed by #11316
Labels

Comments

@kalsan
Copy link

kalsan commented Dec 21, 2022

The following code gets refactored in a wrong way by rubocop -A (with rubocop-rails installed:

Source

def foo(&block)
  block = proc {} unless block_given?
  pass_to_bar(&block)
end

Misbehavior

  • Naming/BlockForwarding: Use anonymous block forwarding
  • Lint/UselessAssignment: Useless assignment to variable - block. but the block is actually used on line 3 (after correction, possibly fixed implicitely when BlockForwarding is fixed)

The code becomes:

def foo(&)
  block = proc {} unless block_given?
  pass_to_bar(&)
end

--> Line 2 is now ineffective and the pass_to_bar crashes then given a nil block.

RuboCop version

1.41.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 3.1.3) [x86_64-linux]
  - rubocop-rails 2.17.3
@kalsan
Copy link
Author

kalsan commented Dec 22, 2022

Thank you, that was blazing fast! Looking forwad to the next release :-)

@koic
Copy link
Member

koic commented Dec 22, 2022

RuboCop 1.41.1 has just been released! You can upgrade to the latest version to fix the bug. Thank you.

@kalsan
Copy link
Author

kalsan commented Dec 22, 2022

Awesome - it works flawlessly! Thanks and have a great day!

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