-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
The autocorrection for Performance/StringIdentifierArgument breaks code #425
Comments
I confirm this in |
Hello 👋 Our project updated rubocop-performance today so we noticed this bug. In addition to the autocorrect being unsafe, this rule matching on string interpolation at all seems (to me) to be incorrect. Rubocop is not able to determine if a string interpolation usage is indeed "redundant". |
Hm, this is a bit unfortunate. The problem isn't the interpolation per se but just passing a symbol with doube colons in the first place. This on its own raises as well: Kernel.const_get(:"MyNamespace::MyClass") I'm actually not sure if this is intended on the side of ruby or not since I'm not finding documentation on this behaviour where I'd expect it. It doesn't seem to recurse if a symbol is given. |
https://bugs.ruby-lang.org/issues/12319 |
[Fix rubocop#425] `const_get` doesn't accept symbols that are something like `:"Foo::Bar"`, and that's intended according to this issue. https://bugs.ruby-lang.org/issues/12319 Therefore, changing String to Symbol might not work as expected. As far as I know that's related to `const_get` only so we can remove it from the target of `StringIdentifierArgument`
[Fix rubocop#425] `const_get` doesn't accept symbols that are something like `:"Foo::Bar"`, and that's intended according to this issue. https://bugs.ruby-lang.org/issues/12319 Therefore, changing String to Symbol might not work as expected. As far as I know that's related to `const_get` only so we can remove it from the target of `StringIdentifierArgument`
Mostly it’s `Performance/StringIdentifierArgument`: methods like `instance_variable_get` or `send` should use symbols, not strings. However, `const_get` does not accepts symbols with nested constants, like `Smth::Setting` (see this issue: rubocop/rubocop-performance#425, which might get fixed by rubocop/rubocop-performance#427). I’ve added `# standard:disable` in `spec/property_sets_spec.rb` until that fix is released.
[Fix #425] Fix a false positive for`Performance/StringIdentifierArgument
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:
Running rubocop on it transforms it to this:
Running the corrected code produces the following error:
RuboCop version
The text was updated successfully, but these errors were encountered: