-
-
Notifications
You must be signed in to change notification settings - Fork 264
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/TimeZone: DateTime.new
is wrongly corrected to DateTime.zone.new
#67
Comments
DateTime.new
is wrongly corrected to DateTime.zone.new
DateTime.new
is wrongly corrected to DateTime.zone.new
rubocop/rubocop#6930 says |
I think there is some confusion related to this cop's behaviour. cc: @vfonic |
@tejasbubane thanks for mentioning me. This is indeed a bug. I think the easiest solution is to make the cop change @doloopwhile thanks for the repro steps! The issue you explained seemed to work for me, until I followed the exact steps and then I saw the bug. Without the detailed repro steps, I would've replied (mistakenly) that the cop works for me and you should check your configuration. Repro steps are important. :) I'm going to submit the PR for this now. |
This removes potential (and actual) bugs due to some methods not being present on `DateTime` class that are present on `Time` class. If we always autocorrect to `Time`, we ensure the most appropriate correction. rubocop#67 rubocop/rubocop#6930 (comment)
Fixes rubocop#67. Closes rubocop#71. This PR fixes an incorrect auto-correct for `Rails/TimeZone` when using `DateTime`. ```diff - DateTime.new + DateTime.zone.new ``` ```ruby DateTime.zone.new # NoMethodError: undefined method `zone' for DateTime:Class ``` This PR changes to ignore `DateTime` with the following as background. `DateTime` is not mentioned in The Rails Style Guide and `Rails/TimeZone` cop's examples. - https://rails.rubystyle.guide/#time-now - https://docs.rubocop.org/projects/rails/en/stable/cops_rails/#railstimezone Recently, rubocop#81 and rubocop#82 have been feedback. I think breaking by auto-correction should be fixed with the highest priority in this case. Also, `DateTime` and `Time` are not replaced from `DateTime` to `Time` by auto-correct because they are different objects.
…ls_time_zone [Fix #67] Fix an incorrect auto-correct for `Rails/TimeZone`
RuboCop Rails 2.2.0 has been released with a fix for this issue. |
When
EnforcedStyle
isflexible
(default),Rails/TimeZone
cop will correctDateTime.new
toDateTime.zone.new
. It breaks codes becauseDateTime.zone
is not defined by Rails.See: https://api.rubyonrails.org/classes/DateTime.html
Expected behavior
DateTime.new
is left as it is.DateTime.new
is corrected toTime.zone.new
asEnforcedTyope: strict
Actual behavior
DateTime.new
is corrected toDateTime.zone.new
Other
DateTime
's methods (now
,local
,parse
,at
,current
) are also corrected toDateTime.zone.*
.Steps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: