Skip to content

Commit

Permalink
Fix false negatives for Style/RedundantRegexpArgument
Browse files Browse the repository at this point in the history
This PR fixes false negatives for `Style/RedundantRegexpArgument`
when using safe navigation operator.
  • Loading branch information
koic authored and bbatsov committed Jul 2, 2023
1 parent ff0effd commit 5998474
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12010](https://github.com/rubocop/rubocop/pull/12010): Fix false negatives for `Style/RedundantRegexpArgument` when using safe navigation operator. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/redundant_regexp_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def on_send(node)
corrector.replace(regexp_node, prefer)
end
end
alias on_csend on_send

private

Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/redundant_regexp_argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
'foo'.#{method}("f")
RUBY
end

it "registers an offense and corrects when the method with safe navigation operator is `#{method}`" do
expect_offense(<<~RUBY, method: method)
'foo'&.#{method}(/f/)
_{method} ^^^ Use string `"f"` as argument instead of regexp `/f/`.
RUBY

expect_correction(<<~RUBY)
'foo'&.#{method}("f")
RUBY
end
end

it 'registers an offense and corrects when using double quote and single quote characters' do
Expand Down

0 comments on commit 5998474

Please sign in to comment.