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

Incorrect auto-correct for Rails/TimeZone, when use String#to_time #1108

Closed
krororo opened this issue Sep 11, 2023 · 0 comments · Fixed by #1115
Closed

Incorrect auto-correct for Rails/TimeZone, when use String#to_time #1108

krororo opened this issue Sep 11, 2023 · 0 comments · Fixed by #1115
Labels
bug Something isn't working

Comments

@krororo
Copy link

krororo commented Sep 11, 2023

Auto-correct for String#to_time expects Time.zone.parse to be added, not .zone.

original code:

'2023-09-11 12:34:56'.to_time

ref: #1094


Expected behavior

Correct to

Time.zone.parse('2023-09-11 12:34:56')

Actual behavior

'2023-09-11 12:34:56'.zone.to_time

Also, ran this code will result in an error.

test.rb:1:in `<main>': undefined method `zone' for "2023-09-11 12:34:56":String (NoMethodError)

'2023-09-11 12:34:56'.zone.to_time
                     ^^^^^

RuboCop version

$ [bundle exec] rubocop -V
1.56.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.1.4) [arm64-darwin22]
  - rubocop-capybara 2.18.0
  - rubocop-factory_bot 2.23.1
  - rubocop-performance 1.19.0
  - rubocop-rails 2.21.0
  - rubocop-rspec 2.24.0
@koic koic added the bug Something isn't working label Sep 11, 2023
koic added a commit to koic/rubocop-rails that referenced this issue Sep 11, 2023
Fixes rubocop#1108.

This PR fixes an incorrect autocorrect for `Rails/TimeZone`
when using `String#to_time`.
koic added a commit that referenced this issue Sep 13, 2023
…ails_time_zone

[Fix #1108] Fix an incorrect autocorrect for `Rails/TimeZone`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants