Skip to content

Commit a02819f

Browse files
committed
Fix a false positive for Rails/RelativeDateConstant when assigning a lambda/proc with numblock
1 parent 2ad3e1a commit a02819f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1458](https://github.com/rubocop/rubocop-rails/pull/1458): Fix a false positive for `Rails/RelativeDateConstant` when assigning a lambda/proc with numblock. ([@earlopain][])

lib/rubocop/cop/rails/relative_date_constant.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def offense_range(name, value)
9090
end
9191

9292
def nested_relative_date(node, &callback)
93-
return if node.nil? || node.block_type?
93+
return if node.nil? || node.any_block_type?
9494

9595
node.each_child_node do |child|
9696
nested_relative_date(child, &callback)

spec/rubocop/cop/rails/relative_date_constant_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ class SomeClass
1818
RUBY
1919
end
2020

21+
it 'accepts a lambda with numblock' do
22+
expect_no_offenses(<<~RUBY)
23+
class SomeClass
24+
EXPIRED_AT = -> { _1.year.ago }
25+
end
26+
RUBY
27+
end
28+
2129
it 'accepts a proc' do
2230
expect_no_offenses(<<~RUBY)
2331
class SomeClass

0 commit comments

Comments
 (0)