Skip to content

Commit 2750e9d

Browse files
committed
Add "Prefer to_fs" rule
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.
1 parent e72a1fc commit 2750e9d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,25 @@ hash.exclude?(:key)
15751575
string.exclude?('substring')
15761576
----
15771577

1578+
=== Prefer `to_fs` for Formatted Strings [[prefer-to-fs]]
1579+
1580+
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.
1581+
1582+
[source,ruby]
1583+
----
1584+
# bad
1585+
time.to_formatted_s(:db)
1586+
date.to_formatted_s(:db)
1587+
datetime.to_formatted_s(:db)
1588+
42.to_formatted_s(:human)
1589+
1590+
# good
1591+
time.to_fs(:db)
1592+
date.to_fs(:db)
1593+
datetime.to_fs(:db)
1594+
42.to_fs(:human)
1595+
----
1596+
15781597
== Time
15791598

15801599
=== Time Zone Config [[tz-config]]

0 commit comments

Comments
 (0)