Skip to content

Commit

Permalink
[Fix rubocop#289] Fix a false positive for `Performance/StringIdentif…
Browse files Browse the repository at this point in the history
…ierArgument`

Fixes rubocop#289.

This PR fixes a false positive for `Performance/StringIdentifierArgument`
when using namespaced class string argument.
  • Loading branch information
koic committed May 18, 2022
1 parent 11dd588 commit b0b47e7
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 b0b47e7

Please sign in to comment.