Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #289] Fix a false positive for Performance/StringIdentifierArgument #290

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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