Skip to content

Commit

Permalink
[Fix rubocop#367] Fix an incorrect autocorrect for `Performance/Block…
Browse files Browse the repository at this point in the history
…GivenWithExplicitBlock`

Fixes rubocop#367.

This PR fixes an incorrect autocorrect for `Performance/BlockGivenWithExplicitBlock`
when using `Lint/UnusedMethodArgument`'s autocorrection together.
  • Loading branch information
ymap committed Aug 26, 2023
1 parent 7d7de79 commit 02b126a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#367](https://github.com/rubocop/rubocop-performance/issues/367): Fix an incorrect autocorrect for `Performance/BlockGivenWithExplicitBlock` when using `Lint/UnusedMethodArgument`'s autocorrection together. ([@ymap][])
8 changes: 8 additions & 0 deletions lib/rubocop-performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@
RuboCop::Performance::Inject.defaults!

require_relative 'rubocop/cop/performance_cops'

RuboCop::Cop::Lint::UnusedMethodArgument.singleton_class.prepend(
Module.new do
def autocorrect_incompatible_with
super.push(RuboCop::Cop::Performance::BlockGivenWithExplicitBlock)
end
end
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def on_send(node)
corrector.replace(node, block_arg_name)
end
end

def self.autocorrect_incompatible_with
[Lint::UnusedMethodArgument]
end
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions spec/rubocop/cli/autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
RUBY
end

it 'corrects `Performance/BlockGivenWithExplicitBlock` with `Lint/UnusedMethodArgument`' do
source = <<~RUBY
def foo(&block)
block_given?
end
RUBY
create_file('example.rb', source)
expect(
cli.run(['--autocorrect', '--only', 'Performance/BlockGivenWithExplicitBlock,Lint/UnusedMethodArgument'])
).to eq(0)
expect(File.read('example.rb')).to eq(<<~RUBY)
def foo()
block_given?
end
RUBY
end

private

def create_file(file_path, content)
Expand Down

0 comments on commit 02b126a

Please sign in to comment.