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

Rails/RelativeDateConstant does not detect some types of relative dates #451

Closed
nc-holodakg opened this issue Mar 25, 2021 · 0 comments · Fixed by #452
Closed

Rails/RelativeDateConstant does not detect some types of relative dates #451

nc-holodakg opened this issue Mar 25, 2021 · 0 comments · Fixed by #452
Labels
bug Something isn't working

Comments

@nc-holodakg
Copy link

RelativeDateConstant looks for constants in a particular format like CONST = <offset>.ago but doesn't consider other forms, such as

START_DATE = 2.weeks.ago.to_date
RECENT_DATE = Date.yesterday
FUTURE_DATE = Time.zone.tomorrow

I looked briefly at the matchers, but I wasn't sure if using ‍`‍ (as described here) would be appropriate to match the relative methods like ago or since with arbitrary levels of nesting.


Expected behavior

RelativeDateConstant adds offenses for a wider variety of relative date constants.

Actual behavior

None of the examples above produce offenses.

Steps to reproduce the problem

# date.rb
START_DATE = 2.weeks.ago.to_date
RECENT_DATE = Date.yesterday
FUTURE_DATE = Time.zone.tomorrow
$ rubocop date.rb

RuboCop version

$ bundle exec rubocop -V
0.93.1 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.1 x86_64-darwin19)

rubocop-rails version is 2.6.0, the logic for this particular cop doesn't seem to have changed since then.

@koic koic added the bug Something isn't working label Mar 25, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Mar 25, 2021
Fixes rubocop#451.

This commit fixes a false negative for `Rails/RelativeDateConstant` when
a method is chained after a relative method.
koic added a commit to koic/rubocop-rails that referenced this issue Mar 25, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Mar 25, 2021
Fixes rubocop#451.

This commit fixes a false negative for `Rails/RelativeDateConstant` when
a method is chained after a relative method.
koic added a commit to koic/rubocop-rails that referenced this issue Mar 25, 2021
koic added a commit to koic/rubocop-rails that referenced this issue Mar 25, 2021
Fixes rubocop#451.

This commit fixes a false negative for `Rails/RelativeDateConstant` when
a method is chained after a relative date method.
koic added a commit to koic/rubocop-rails that referenced this issue Mar 25, 2021
@koic koic closed this as completed in #452 Mar 27, 2021
koic added a commit that referenced this issue Mar 27, 2021
…ve_date_constant

[Fix #451] Fix a false negative for `Rails/RelativeDateConstant`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants