-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Description
I suspect this is caused by some change with #12754. I admit the following report was mostly generated by AI.
Steps to reproduce the problem
Create a file example.rb with this content:
# frozen_string_literal: true
class Example
def initialize
@info = {
last_failure: if some_condition
some_value
end,
last_result: if another_condition
another_value
end,
parent: if yet_another
some_object
end,
root: if final_condition
final_value
end
}
end
endRun:
rubocop --only Style/IfUnlessModifier example.rbExpected behavior
Process the code
Actual behavior
RuboCop crashes with a NoMethodError:
An error occurred while Style/IfUnlessModifier cop was inspecting example.rb:6:19.
To see the complete backtrace run rubocop -d.
With rubocop -d:
/home/cretz/.asdf/installs/ruby/4.0.0/lib/ruby/gems/4.0.0/gems/rubocop-1.84.1/lib/rubocop/cop/style/if_unless_modifier.rb:267:in 'RuboCop::Cop::Style::IfUnlessModifier#shares_line_with?': undefined method 'line' for nil (NoMethodError)
inner.loc.line == node.loc.end.line || inner.loc.end.line == node.loc.line
^^^^^
The cop attempts to call .line on a nil loc.end object when analyzing multi-line if statements used as hash values.
RuboCop version
$ bundle exec rubocop -V
1.84.1 (using Parser 3.3.10.1, Prism 1.9.0, rubocop-ast 1.49.0, analyzing as Ruby 3.3, running on ruby 4.0.0) [x86_64-linux]
To workaround, 1.84.0 can be pinned as the Rubocop version.
Reactions are currently unavailable