Skip to content

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

Closed
@nc-holodakg

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions