String with interpolated boolean causes the Lint/EmptyInterpolation
cop to crash.
It's similar to #14248 and is not fixed by #14245.
This string would cause a crash: "This is #{true} or #{false}"
Got the following error:
An error occurred while Lint/EmptyInterpolation cop was inspecting /Users/cbliard/code/opf/openproject/empty_interpolation.rb:1:0.
/Users/cbliard/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.76.1/lib/rubocop/cop/lint/empty_interpolation.rb:23:in 'block in RuboCop::Cop::Lint::EmptyInterpolation#on_interpolation': undefined method 'value' for an instance of RuboCop::AST::Node (NoMethodError)
node_children.delete_if { |e| e.nil_type? || (e.basic_literal? && e.value.to_s.empty?) }
^^^^^^
Steps to reproduce the problem
commands:
echo '"This is #{true} or #{false}"' > empty_interpolation.rb
rubocop _1.76.1_ --debug --only Lint/EmptyInterpolation empty_interpolation.rb
partial output:
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/cbliard/code/opf/openproject/empty_interpolation.rb
An error occurred while Lint/EmptyInterpolation cop was inspecting /Users/cbliard/code/opf/openproject/empty_interpolation.rb:1:0.
/Users/cbliard/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.76.1/lib/rubocop/cop/lint/empty_interpolation.rb:23:in 'block in RuboCop::Cop::Lint::EmptyInterpolation#on_interpolation': undefined method 'value' for an instance of RuboCop::AST::Node (NoMethodError)
node_children.delete_if { |e| e.nil_type? || (e.basic_literal? && e.value.to_s.empty?) }
^^^^^^
from /Users/cbliard/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.76.1/lib/rubocop/cop/lint/empty_interpolation.rb:23:in 'Array#delete_if'
from /Users/cbliard/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.76.1/lib/rubocop/cop/lint/empty_interpolation.rb:23:in 'RuboCop::Cop::Lint::EmptyInterpolation#on_interpolation'
from /Users/cbliard/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-1.76.1/lib/rubocop/cop/mixin/interpolation.rb:18:in 'block in RuboCop::Cop::Interpolation#on_node_with_interpolations'
from /Users/cbliard/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.45.1/lib/rubocop/ast/node/mixin/descendence.rb:28:in 'block in RuboCop::AST::Descendence#each_child_node'
from /Users/cbliard/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.45.1/lib/rubocop/ast/node/mixin/descendence.rb:25:in 'Array#each'.
[...]
1 file inspected, no offenses detected
1 error occurred:
An error occurred while Lint/EmptyInterpolation cop was inspecting /Users/cbliard/code/opf/openproject/empty_interpolation.rb:1:0.
configuration from /Users/cbliard/.rubocop.yml
Errors are usually caused by RuboCop bugs.
Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.76.1 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.1, analyzing as Ruby 3.3, running on ruby 3.4.4) [arm64-darwin24]
Finished in 0.047657000133767724 seconds
Alternatively, editing test spec/rubocop/cop/lint/empty_interpolation_spec.rb:74
and replacing #{1}
by #{true}
and then running bundle exec rspec spec/rubocop/cop/lint/empty_interpolation_spec.rb
works well too to reproduce the issue.
$ rubocop _1.76.1_ -V
1.76.1 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.1, analyzing as Ruby 3.3, running on ruby 3.4.4) [arm64-darwin24]
Also tested with 7551f0f
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4