Skip to content

Commit

Permalink
[Fix rubocop#10737] Fix crash in Style/ConditionalAssignment with `…
Browse files Browse the repository at this point in the history
…EnforcedStyle: assign_inside_condition` when op-assigning a variable inside a `resbody`.
  • Loading branch information
dvandersluis committed Jun 22, 2022
1 parent 0d09460 commit 9876f51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_fix_crash_in_styleconditionalassignment.md
@@ -0,0 +1 @@
* [#10737](https://github.com/rubocop/rubocop/issues/10737): Fix crash in `Style/ConditionalAssignment` with `EnforcedStyle: assign_inside_condition` when op-assigning a variable inside a `resbody`. ([@dvandersluis][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/conditional_assignment.rb
Expand Up @@ -237,6 +237,7 @@ class ConditionalAssignment < Base
ASSIGNMENT_TYPES.each do |type|
define_method "on_#{type}" do |node|
return if part_of_ignored_node?(node)
return if node.parent&.shorthand_asgn?

check_assignment_to_condition(node)
end
Expand Down
Expand Up @@ -242,6 +242,16 @@
end
RUBY
end

it 'does not crash when used inside rescue' do
expect_no_offenses(<<~RUBY)
begin
bar #{assignment} 2
rescue
bar #{assignment} 1
end
RUBY
end
end

shared_examples 'multiline all variable types offense' do |variable|
Expand Down

0 comments on commit 9876f51

Please sign in to comment.