Skip to content

The autocorrection for Performance/StringIdentifierArgument breaks code #425

@davidenglishmusic

Description

@davidenglishmusic

Expected behavior

The cop's autocorrection should not break code.

Actual behavior

The cop's autocorrection breaks code.

Steps to reproduce the problem

The following code runs:

# frozen_string_literal: true

module MyNamespace
  class MyClass
  end
end

prefix = 'MyNamespace::'
class_name = 'MyClass'
Kernel.const_get("#{prefix}#{class_name}")

Running rubocop on it transforms it to this:

# frozen_string_literal: true

module MyNamespace
  class MyClass
  end
end

prefix = 'MyNamespace::'
class_name = 'MyClass'
Kernel.const_get(:"#{prefix}#{class_name}")

Running the corrected code produces the following error:

app.rb:10:in `const_get': wrong constant name MyNamespace::MyClass (NameError)

Kernel.const_get(:"#{prefix}#{class_name}")
      ^^^^^^^^^^
	from app.rb:10:in `<main>'

RuboCop version

1.59.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.1.1) [x86_64-linux]
  - rubocop-performance 1.20.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions