rubocop / rails-style-guide

A community-driven Ruby on Rails style guide
http://rails.rubystyle.guide
6.48k stars 1.06k forks source link

Add time comparison guideline #357

Open pirj opened 4 months ago

pirj commented 4 months ago

past?/future?

Noteable offenders:

- if reminder_at < Time.zone.now
+ if reminder_at.past?
- sleep 1 if alarm_at > Time.zone.now
+ sleep 1 if alarm_at.future?

Rails docs:

Secondary, informative section:

Introduction of before?/after? in Rails 6.0.

before?/after? didn't make to this guideline due to insufficient use, and it would go against our:

A style guide that reflects real-world usage gets used, and a style guide that holds to an ideal that has been rejected by the people it is supposed to help risks not getting used at all - no matter how good it is.

- last_archival_attempt_at + backoff < Time.current
+ last_archival_attempt_at.before? backoff.from_now