You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The autocorrection for Performance/ConstantRegexp should fix the offense even with pattern matching.
Actual behavior
The autocorrection for Performance/ConstantRegexp prepends the end delimiter /o, leading to the following error:
NODE_IN: unknownnode(NODE_ONCE)
Steps to reproduce the problem
I have a method that uses pattern matching:
# constants/errors.rbUNINITIALIZED_CONSTANT="uninitialized constant".freezeUNDEFINED_VARIABLE="undefined local variable".freezedefcallcaseexception.messagein/#{Constants::Errors::UNINITIALIZED_CONSTANT}/# do somethingin/#{Constants::Errors::UNDEFINED_VARIABLE}/# do somethingelse# do somethingendend
It works well but rubocop-performance raises the following offense:
# constants/errors.rbUNINITIALIZED_CONSTANT="uninitialized constant".freezeUNDEFINED_VARIABLE="undefined local variable".freezedefcallcaseexception.messagein/#{Constants::Errors::UNINITIALIZED_CONSTANT}/o# do somethingin/#{Constants::Errors::UNDEFINED_VARIABLE}/o# do somethingelse# do somethingendend
and it breaks the code with the following error:
NODE_IN: unknownnode(NODE_ONCE)
FYI I tried an if/else version and it works correctly
defcallifexception.message.match?(/#{Constants::Errors::UNINITIALIZED_CONSTANT}/o)# do somethingelsifexception.message.match?(/#{Constants::Errors::UNDEFINED_VARIABLE}/o)# do somethingelse# do somethingendend
RuboCop version
rubocop (1.57.2)
rubocop-performance (1.19.1)
Note: I use the standard gem
The text was updated successfully, but these errors were encountered:
classScriptUNINITIALIZED_CONSTANT="uninitialized constant".freezeUNDEFINED_VARIABLE="undefined local variable".freezeclassErrordefself.call(exception)caseexceptionin/#{UNINITIALIZED_CONSTANT}/p"UNINITIALIZED_CONSTANT"in/#{UNDEFINED_VARIABLE}/p"UNDEFINED_VARIABLE"else# noopendendendError.call(UNINITIALIZED_CONSTANT)end
2/ Run rubocop (as mentioned I use standard)
output:
script.rb:9:10: C: [Correctable] Performance/ConstantRegexp: Extract this regexp into a constant, memoize it, or append an /o option to its options.
in /#{UNINITIALIZED_CONSTANT}/
^^^^^^^^^^^^^^^^^^^^^^^^^^^
script.rb:11:10: C: [Correctable] Performance/ConstantRegexp: Extract this regexp into a constant, memoize it, or append an /o option to its options.
in /#{UNDEFINED_VARIABLE}/
Expected behavior
The autocorrection for
Performance/ConstantRegexp
should fix the offense even with pattern matching.Actual behavior
The autocorrection for
Performance/ConstantRegexp
prepends the end delimiter/o
, leading to the following error:Steps to reproduce the problem
I have a method that uses pattern matching:
It works well but
rubocop-performance
raises the following offense:The autocorrect prepends
/o
and it breaks the code with the following error:
FYI I tried an
if/else
version and it works correctlyRuboCop version
Note: I use the
standard
gemThe text was updated successfully, but these errors were encountered: