-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Description
I found an interesting bug, Lint/LiteralAsCondition auto-correct was causing a syntax error. But I realized after checking more deeply, that the code was never doing what it was supposed to do, so not sure if this is still something that should be addressed or not.
Expected behavior
Not sure :)
Actual behavior
❯ ruby test.rb
test.rb: --> test.rb
unexpected void value expression
1 def my_method(param)
> 2 puts return if param.nil?
> 3 puts param
4 end
test.rb:2: void value expression (SyntaxError)
puts return if param.nil?
Steps to reproduce the problem
We have code like this, where param is checked and if it's not there we wanted to log (replaced by puts for the example) and return
def my_method(param)
puts "param was nil" && return if param.nil?
puts param
end
This get's corrected to
def my_method(param)
puts return if param.nil?
puts param
end
causing the SyntaxError, but even without it, the code was never logging, but just returned nil.
After fixing it to be puts("param is nil") && return if param.nil? Lint/LiteralAsCondition didn't complain anymore about it.
RuboCop version
❯ bundle exec rubocop -V
1.73.2 (using Parser 3.3.7.1, rubocop-ast 1.38.1, analyzing as Ruby 3.3, running on ruby 3.3.7) [arm64-darwin24]
- rubocop-rails 2.30.3
Reactions are currently unavailable