Open morissetcl opened 9 months ago
Can you provide an executable code and steps to reproduce the NODE_IN: unknown node (NODE_ONCE)
error?
Yes sure:
1/ Run the code below ruby script.rb
class Script
UNINITIALIZED_CONSTANT = "uninitialized constant".freeze
UNDEFINED_VARIABLE = "undefined local variable".freeze
class Error
def self.call(exception)
case exception
in /#{UNINITIALIZED_CONSTANT}/
p "UNINITIALIZED_CONSTANT"
in /#{UNDEFINED_VARIABLE}/
p "UNDEFINED_VARIABLE"
else
# noop
end
end
end
Error.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}/
3/ Run the autocorrect command
output:
script.rb: script.rb:5: NODE_IN: unknown node (NODE_ONCE) (SyntaxError)
Thanks.
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
gem