-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Description
Lint/EmptyInterpolation does not understand that being inside %W affects behavior; Auto-correct changes program semantics:
3.4.6 :001 > %W[#{''} test]
=> ["", "test"]
3.4.6 :002 > %W[ test]
=> ["test"]
Steps to reproduce the problem
# in example.rb
def foo
parts = %W[#{""} one two]
raise StandardError if parts.length < 3
puts "done"
end
fooRunning ruby example.rb prints "done" to the console.
Expected behavior
Running rubocop --only Lint/EmptyInterpolation --autocorrect example.rb should not change the file.
Actual behavior
Inspecting 1 file
W
Offenses:
example.rb:2:14: W: [Corrected] Lint/EmptyInterpolation: Empty interpolation detected.
parts = %W[#{""} one two]
^^^^^
1 file inspected, 1 offense detected, 1 offense corrected
The file is incorrectly changed to:
def foo
parts = %W[ one two]
raise StandardError if parts.length < 3
puts "done"
end
fooRunning ruby example.rb now errors:
example.rb:3:in 'Object#foo': StandardError (StandardError)
from example.rb:7:in '<main>'
RuboCop version
rubocop -V
1.80.2 (using Parser 3.3.9.0, rubocop-ast 1.47.1, analyzing as Ruby 2.7, running on ruby 3.4.6) [arm64-darwin24]