Skip to content

Commit

Permalink
Add "Prefer to_fs" rule
Browse files Browse the repository at this point in the history
Follow up rails/rails#44354.

Also, the deprecated warning for `to_s(:db)` is `to_fs(:db)` instead of `to_formatted_s(:db)`.

> DateTime#to_s(:db) is deprecated. Please use DateTime#to_fs(:db) instead.
  • Loading branch information
koic committed Apr 16, 2022
1 parent e72a1fc commit 4af97d7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,25 @@ hash.exclude?(:key)
string.exclude?('substring')
----

=== Prefer `to_fs` [[prefer-to-fs]]

If you're using Rails 7.0 or higher, prefer `to_fs` over `to_formatted_s`. `to_formatted_s` is just too cumbersome for a method used that frequently.

[source,ruby]
----
# bad
time.to_formatted_s(:db)
date.to_formatted_s(:db)
datetime.to_formatted_s(:db)
42.to_formatted_s(:human)
# good
time.to_fs(:db)
date.to_fs(:db)
datetime.to_fs(:db)
42.to_fs(:human)
----

== Time

=== Time Zone Config [[tz-config]]
Expand Down

0 comments on commit 4af97d7

Please sign in to comment.