Skip to content

Commit d18b3c9

Browse files
committed
Fix false negatives in Style/MapIntoArray autocorrection when using ensure, def, defs and for
1 parent 3277118 commit d18b3c9

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#13185](https://github.com/rubocop/rubocop/pull/13185): Fix false negatives in `Style/MapIntoArray` autocorrection when using `ensure`, `def`, `defs` and `for`. ([@vlad-pisanov][])

lib/rubocop/cop/style/map_into_array.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ def return_value_used?(node)
147147
false
148148
when :begin, :kwbegin
149149
!node.right_sibling && return_value_used?(parent)
150-
when :block, :numblock
151-
!parent.void_context?
152150
else
153-
true
151+
!parent.respond_to?(:void_context?) || !parent.void_context?
154152
end
155153
end
156154

spec/rubocop/cop/style/map_into_array_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@
374374
it_behaves_like 'corrects', template: 'begin; %s end'
375375
end
376376
end
377+
378+
context 'in an ensure' do
379+
it_behaves_like 'corrects', template: 'begin; ensure; %s end'
380+
end
377381
end
378382

379383
context 'in a block' do
@@ -404,6 +408,18 @@
404408
context 'at the end' do
405409
it_behaves_like 'skip correcting', template: 'def foo; %s end'
406410
end
411+
412+
context 'in a constructor' do
413+
it_behaves_like 'corrects', template: 'def initialize; %s; end'
414+
end
415+
416+
context 'in an assignment method' do
417+
it_behaves_like 'corrects', template: 'def foo=(value); %s; end'
418+
end
419+
end
420+
421+
context 'in a for loop' do
422+
it_behaves_like 'corrects', template: 'for i in foo; %s; end'
407423
end
408424
end
409425
end

0 commit comments

Comments
 (0)