From b6593788d43884b2b840e4f49144e68cdf19b25b Mon Sep 17 00:00:00 2001 From: Zopolis4 Date: Sat, 28 Sep 2024 16:48:44 +1000 Subject: [PATCH] Add "Empty Strings In Interpolation" rule. --- README.adoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.adoc b/README.adoc index 132e6c29..afb11d8a 100644 --- a/README.adoc +++ b/README.adoc @@ -4910,6 +4910,20 @@ message = "This is the #{result.to_s}." message = "This is the #{result}." ---- +=== Empty Strings In Interpolation [[empty-strings-in-interpolation]] + +Don't assign empty strings inside string interpolation. +For conditionals, use modifier statements instead of ternaries with empty strings. + +[source,ruby] +---- +# bad +"#{condition ? 'foo' : ''}" + +# good +"#{'foo' if condition}" +---- + === String Concatenation [[concat-strings]] Avoid using `pass:[String#+]` when you need to construct large data chunks.