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

Cop idea: use all_day instead of manually creating the day range #486

Closed
Darhazer opened this issue May 14, 2021 · 3 comments · Fixed by #487
Closed

Cop idea: use all_day instead of manually creating the day range #486

Darhazer opened this issue May 14, 2021 · 3 comments · Fixed by #487
Labels
feature request Request for new functionality

Comments

@Darhazer
Copy link
Member

Is your feature request related to a problem? Please describe.

I've seen (and wrote) a lot of the .where(some_date_field: date.beginning_of_day..date.end_of_day) code.
Today I learned there is .all_day shortcut for that.

Describe the solution you'd like

A cop to promote the above would be nice

@andyw8
Copy link
Contributor

andyw8 commented May 14, 2021

Implementation note: Available since Rails 5.1

@dvandersluis
Copy link
Member

There’s also all_week, all_month and all_year (And all_quarter but it’d be harder to autocorrect to that reliably)

@koic koic added the feature request Request for new functionality label May 14, 2021
@koic
Copy link
Member

koic commented May 16, 2021

koic added a commit to koic/rubocop-rails that referenced this issue May 17, 2021
Fixes rubocop#486.

This PR adds new `Rails/ExpandedDateRange` cop that checks for expanded date range.
It only compatible `..` range is targeted. Incompatible `...` range is ignored.

```ruby
# bad
date.beginning_of_day..date.end_of_day
date.beginning_of_week..date.end_of_week
date.beginning_of_month..date.end_of_month
date.beginning_of_quarter..date.end_of_quarter
date.beginning_of_year..date.end_of_year

# good
date.all_day
date.all_week
date.all_month
date.all_quarter
date.all_year
```
koic added a commit to koic/rubocop-rails that referenced this issue May 17, 2021
Fixes rubocop#486.

This PR adds new `Rails/ExpandedDateRange` cop that checks for expanded date range.
It only compatible `..` range is targeted. Incompatible `...` range is ignored.

```ruby
# bad
date.beginning_of_day..date.end_of_day
date.beginning_of_week..date.end_of_week
date.beginning_of_month..date.end_of_month
date.beginning_of_quarter..date.end_of_quarter
date.beginning_of_year..date.end_of_year

# good
date.all_day
date.all_week
date.all_month
date.all_quarter
date.all_year
```
@koic koic closed this as completed in #487 May 23, 2021
koic added a commit that referenced this issue May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants