Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a false positive for Rails/RelativeDateConstant when assigning a lambda/proc with numblock #1458

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +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][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/relative_date_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def offense_range(name, value)
end

def nested_relative_date(node, &callback)
return if node.nil? || node.block_type?
return if node.nil? || node.any_block_type?

node.each_child_node do |child|
nested_relative_date(child, &callback)
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/relative_date_constant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class SomeClass
RUBY
end

it 'accepts a lambda with numblock' do
expect_no_offenses(<<~RUBY)
class SomeClass
EXPIRED_AT = -> { _1.year.ago }
end
RUBY
end

it 'accepts a proc' do
expect_no_offenses(<<~RUBY)
class SomeClass
Expand Down
Loading