Skip to content

Commit dde963d

Browse files
committed
Add "Prefer using squiggly heredoc over strip_heredoc" rule
Follow up rubocop/rubocop-rails#706. This PR adds "Prefer using squiggly heredoc over `strip_heredoc`" rule.
1 parent 73b9c68 commit dde963d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.adoc

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

1578+
=== Prefer using squiggly heredoc over `strip_heredoc` [[prefer-squiggly-heredoc]]
1579+
1580+
If you're using Ruby 2.3 or higher, prefer squiggly heredoc (`<<~`) over Active Support's `strip_heredoc`.
1581+
1582+
[source,ruby]
1583+
----
1584+
# bad
1585+
<<EOS.strip_heredoc
1586+
some text
1587+
EOS
1588+
1589+
# bad
1590+
<<-EOS.strip_heredoc
1591+
some text
1592+
EOS
1593+
1594+
# good
1595+
<<~EOS
1596+
some text
1597+
EOS
1598+
----
1599+
15781600
=== Prefer `to_fs` for Formatted Strings [[prefer-to-fs]]
15791601

15801602
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.

0 commit comments

Comments
 (0)