File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change
1
+ * [ #14418 ] ( https://github.com/rubocop/rubocop/pull/14418 ) : Fix false positives for ` Style/MapToSet ` when using ` to_set ` with block argument. ([ @koic ] [ ] )
Original file line number Diff line number Diff line change @@ -40,12 +40,10 @@ class MapToSet < Base
40
40
41
41
def on_send ( node )
42
42
return unless ( to_set_node , map_node = map_to_set? ( node ) )
43
+ return if to_set_node . block_literal?
43
44
44
45
message = format ( MSG , method : map_node . loc . selector . source )
45
46
add_offense ( map_node . loc . selector , message : message ) do |corrector |
46
- # If the `to_set` call already has a block, do not autocorrect.
47
- next if to_set_node . block_literal?
48
-
49
47
autocorrect ( corrector , to_set_node , map_node )
50
48
end
51
49
end
Original file line number Diff line number Diff line change 116
116
end
117
117
end
118
118
119
- context "`#{ method } .to_set` with a block on `to_set`" do
120
- it 'registers an offense but does not correct' do
121
- expect_offense ( <<~RUBY , method : method )
119
+ context "`#{ method } ` followed by `to_set` with a block passed to `to_set`" do
120
+ it 'does not register an offense but does not correct' do
121
+ expect_no_offenses ( <<~RUBY )
122
+ foo.#{ method } { |x| x * 2 }.to_set { |x| [x.to_s, x] }
123
+ RUBY
124
+ end
125
+ end
126
+
127
+ context "`#{ method } ` followed by `to_set` with a numbered block passed to `to_set`" , :ruby27 do
128
+ it 'does not register an offense but does not correct' do
129
+ expect_no_offenses ( <<~RUBY )
122
130
foo.#{ method } { |x| x * 2 }.to_set { |x| [x.to_s, x] }
123
- ^{method} Pass a block to `to_set` instead of calling `#{ method } .to_set`.
124
131
RUBY
132
+ end
133
+ end
125
134
126
- expect_no_corrections
135
+ context "`#{ method } ` followed by `to_set` with an `it` block passed to `to_set`" , :ruby34 do
136
+ it 'does not register an offense but does not correct' do
137
+ expect_no_offenses ( <<~RUBY )
138
+ foo.#{ method } { |x| x * 2 }.to_set { |x| [x.to_s, x] }
139
+ RUBY
127
140
end
128
141
end
129
142
You can’t perform that action at this time.
0 commit comments