When both Performance/BlockGivenWithExplicitBlock and Lint/UnusedMethodArgument cops are enabled, there seem to be cases where the autocorrect introduces incorrect behavior. This specifically occurs in method definitions with the following characteristics:
The block argument is explicitly declared.
This argument remains unused within the method.
The method invokes block_given?.
Here's a sample code to illustrate the issue:
def foo(&block)
block_given?
end
Expected Behavior
Only one of the cop's autocorrects should be executed. Ideally, the code should be:
def foo
block_given?
end
or
def foo(&block)
block
end
Actual Behavior
The autocorrect results in:
def foo
block
end
This leads to the code referencing an undefined variable block, thus deviating from the intended functionality.
When both
Performance/BlockGivenWithExplicitBlock
andLint/UnusedMethodArgument
cops are enabled, there seem to be cases where the autocorrect introduces incorrect behavior. This specifically occurs in method definitions with the following characteristics:block_given?
.Here's a sample code to illustrate the issue:
Expected Behavior
Only one of the cop's autocorrects should be executed. Ideally, the code should be:
or
Actual Behavior
The autocorrect results in:
This leads to the code referencing an undefined variable
block
, thus deviating from the intended functionality.Steps to Reproduce
example.rb
.bundle exec rubocop -a example.rb
.RuboCop Version