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 with Rails/RelativeDateConstant #482

Merged
merged 1 commit into from
May 11, 2021

Conversation

jdelStrother
Copy link
Contributor

Prior to this, procs would only be allowed for the top-level assignment - eg

FOO = 1.week.ago # bad
FOO = Proc.new { 1.week.ago } # good

but didn't accept cases where the Proc was nested further down, eg:

FOO = {
  weekly: Proc.new { 1.week.ago } # bad (but should be good!)
}

This patch changes the RelativeDateConstant to recursive down through
the child nodes of the const-assignment, stopping whenever a Proc is
encountered.

As a result, ranges no longer need special-casing, so I've removed the
handling for those.

@jdelStrother
Copy link
Contributor Author

jdelStrother commented May 11, 2021

(uhh - don't commit this yet, think I just spotted something dumb)

nvm, it's fine 😛

@jdelStrother jdelStrother marked this pull request as draft May 11, 2021 09:17
@jdelStrother jdelStrother marked this pull request as ready for review May 11, 2021 09:26
Copy link
Member

@koic koic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the caching up! I've wrote several comments. Please squash commits into one when you're done.

lib/rubocop/cop/rails/relative_date_constant.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Prior to this, procs would only be allowed for the top-level assignment
- eg

FOO = 1.week.ago # bad
FOO = Proc.new { 1.week.ago } # good

but didn't accept cases where the Proc was nested further down, eg:

FOO = {
  weekly: Proc.new { 1.week.ago } # bad (but should be good!)
}

This patch changes the RelativeDateConstant to recursive down through
the child nodes of the const-assignment, stopping whenever a Proc is
encountered.

As a result, ranges no longer need special-casing, so I've removed the
handling for those.
@jdelStrother
Copy link
Contributor Author

Thanks, done

@koic koic merged commit 3683d92 into rubocop:master May 11, 2021
@koic
Copy link
Member

koic commented May 11, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants