Skip to content

Commit

Permalink
Merge pull request #290 from koic/fix_a_false_positive_for_performanc…
Browse files Browse the repository at this point in the history
…e_string_identifier_argument

[Fix #289] Fix a false positive for `Performance/StringIdentifierArgument`
  • Loading branch information
koic authored May 21, 2022
2 parents 11dd588 + b0b47e7 commit 9dba637
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#289](https://github.com/rubocop/rubocop-performance/issues/289): Fix a false positive for `Performance/StringIdentifierArgument` when using namespaced class string argument. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/string_identifier_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class StringIdentifierArgument < Base
def on_send(node)
return unless (first_argument = node.first_argument)
return unless first_argument.str_type?
return if first_argument.value.include?(' ')
return if first_argument.value.include?(' ') || first_argument.value.include?('::')

replacement = first_argument.value.to_sym.inspect

Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/performance/string_identifier_argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
RUBY
end

it 'does not register an offense when using cbase class string argument' do
expect_no_offenses(<<~RUBY)
Object.const_defined?('::Foo')
RUBY
end

it 'does not register an offense when using namespaced class string argument' do
expect_no_offenses(<<~RUBY)
Object.const_defined?('Foo::Bar')
RUBY
end

it 'does not register an offense when using symbol argument for no identifier argument' do
expect_no_offenses(<<~RUBY)
foo('do_something')
Expand Down

0 comments on commit 9dba637

Please sign in to comment.