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

[Fix #67] Fix an incorrect auto-correct for `Rails/TimeZone` #85

Conversation

@koic
Copy link
Member

commented Jul 5, 2019

Fixes #67.
Closes #71.

This PR fixes an incorrect auto-correct for Rails/TimeZone when using DateTime.

- DateTime.new
+ DateTime.zone.new
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.

Recently, #81 and #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.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.
[Fix #67] Fix an incorrect auto-correct for `Rails/TimeZone`
Fixes #67.
Closes #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, #81 and #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.

@koic koic merged commit 9b2285f into rubocop-hq:master Jul 6, 2019

6 checks passed

ci/circleci: JRuby 9.2 Your tests passed on CircleCI!
Details
ci/circleci: Ruby 2.3 Your tests passed on CircleCI!
Details
ci/circleci: Ruby 2.4 Your tests passed on CircleCI!
Details
ci/circleci: Ruby 2.5 Your tests passed on CircleCI!
Details
ci/circleci: Ruby 2.6 Your tests passed on CircleCI!
Details
ci/circleci: Ruby HEAD Your tests passed on CircleCI!
Details

@koic koic deleted the koic:fix_an_incorrect_autocorrect_for_rails_time_zone branch Jul 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.