Skip to content

Commit

Permalink
Merge pull request #478 from viralpraxis/fix-performance-redundant-st…
Browse files Browse the repository at this point in the history
…ring-chars-cop-error-in-case-of-implicit-receiver

Fix `Performance/RedundantStringChars` cop error in case of implicit receiver
  • Loading branch information
koic authored Dec 11, 2024
2 parents 378299f + ccb9241 commit 9248192
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#478](https://github.com/rubocop/rubocop-performance/pull/478): Fix `Performance/RedundantStringChars` cop error in case of implicit receiver. ([@viralpraxis][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/redundant_string_chars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RedundantStringChars < Base
RESTRICT_ON_SEND = %i[[] slice first last take length size empty?].freeze

def_node_matcher :redundant_chars_call?, <<~PATTERN
(send $(send _ :chars) $_ $...)
(send $(send !nil? :chars) $_ $...)
PATTERN

def on_send(node)
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/performance/redundant_string_chars_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,10 @@
str.chars.max
RUBY
end

it 'does not register an offense with implicit receiver' do
expect_no_offenses(<<~RUBY)
chars.size
RUBY
end
end

0 comments on commit 9248192

Please sign in to comment.