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 an incorrect autocorrect for Rails/TimeZone when Time.new has a string argument #1397

Merged
merged 1 commit into from
Dec 28, 2024

Conversation

mterada1228
Copy link
Contributor

@mterada1228 mterada1228 commented Dec 21, 2024

This PR fixes incorrect autocorrect for Rails/TimeZone when Time.new has a string argument.

Expected Behavior

# Before autocorrect
Time.new("2024-12-21 12:00:00")

# After autocorrect
Time.zone.parse("2024-12-21 12:00:00")

Actual Behavior

# Before autocorrect
Time.new("2024-12-21 12:00:00")

# After autocorrect
Time.zone.local("2024-12-21 12:00:00")

Autocorrected code doesn't work.

irb(main):002> Time.zone.local("2024-12-21 12:00:00")
(irb):2:in `<main>': invalid value for Integer(): "2024-12-21 12:00:00" (ArgumentError)

      time = Time.utc(*args)
                      ^^^^^

Steps to reproduce the problem

Run bundle ex rubocop -a --only Rails/TimeZone on the code below:

Time.new("2024-12-21 12:00:00")

RuboCop version

rubocop -v
1.68.0

Replace this text with a summary of the changes in your PR.
The more detailed you are, the better.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@mterada1228 mterada1228 marked this pull request as draft December 21, 2024 08:54
@mterada1228 mterada1228 marked this pull request as ready for review December 21, 2024 09:03
@mterada1228 mterada1228 changed the title Fix an incorrect autocorrect for Rails/TimeZone when Time.new has a string argument. Fix an incorrect autocorrect for Rails/TimeZone when Time.new has a string argument Dec 21, 2024
@mterada1228
Copy link
Contributor Author

@koic

Thanks!
I totally agree with your suggestion and apply it.

@koic
Copy link
Member

koic commented Dec 26, 2024

@mterada1228 This looks good to me. Can you squash your commits into one?

@mterada1228
Copy link
Contributor Author

@koic

Thank you for your review.
I squashed my commits into one.

@koic koic merged commit 8f625ad into rubocop:master Dec 28, 2024
14 checks passed
@koic
Copy link
Member

koic commented Dec 28, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants