File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ class CompactBlank < Base
80
80
PATTERN
81
81
82
82
def on_send ( node )
83
+ return if target_ruby_version < 2.6 && node . method? ( :filter )
83
84
return unless bad_method? ( node )
84
85
85
86
range = offense_range ( node )
Original file line number Diff line number Diff line change @@ -257,6 +257,27 @@ def foo(arg)
257
257
collection.filter { |e| e.blank? }
258
258
RUBY
259
259
end
260
+
261
+ context 'target_ruby_version >= 2.6' , :ruby26 do
262
+ it 'registers and corrects an offense when using `filter { |e| e.present? }`' do
263
+ expect_offense ( <<~RUBY )
264
+ collection.filter { |e| e.present? }
265
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank` instead.
266
+ RUBY
267
+
268
+ expect_correction ( <<~RUBY )
269
+ collection.compact_blank
270
+ RUBY
271
+ end
272
+ end
273
+
274
+ context 'target_ruby_version < 2.6' , :ruby25 , unsupported_on : :prism do
275
+ it 'does not register an offense when using `filter { |e| e.present? }`' do
276
+ expect_no_offenses ( <<~RUBY )
277
+ collection.filter { |e| e.present? }
278
+ RUBY
279
+ end
280
+ end
260
281
end
261
282
262
283
context 'Rails <= 6.0' , :rails60 do
You can’t perform that action at this time.
0 commit comments