roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

RCS1197 does not know about `AppendInterpolatedStringHandler`

Open jnyrup opened this issue 3 years ago • 1 comments
trafficstars

Product and Version Used: v4.1.0

Steps to Reproduce: C# 10 introduced Improved Interpolated Strings and .NET 6 added an overload StringBuilder.Append(ref AppendInterpolatedStringHandler) which lets you write

new StringBuilder().Append($"13{37}");

and at compile time it is translated into

StringBuilder stringBuilder = new StringBuilder();
StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(2, 1, stringBuilder);
handler.AppendLiteral("13");
handler.AppendFormatted(37);
stringBuilder.Append(ref handler);

SharpLab

image image

Actual Behavior: RCS1197 is reported

Expected Behavior: RCS1197 should not be reported

jnyrup avatar Apr 29 '22 08:04 jnyrup

Confirmed here also, and I think that:

arguments.Append($" CONTENTDIR=\"{destinationPath}\"");

Really does look much clearer than:

arguments.Append(" CONTENTDIR=\"").Append(destinationPath).Append('\"');

😸

fgimian avatar Aug 29 '22 11:08 fgimian

any update on this bug?

udlose avatar Jan 20 '24 22:01 udlose

Confirmed here also, and I think that:

arguments.Append($" CONTENTDIR=\"{destinationPath}\"");

Really does look much clearer than:

arguments.Append(" CONTENTDIR=\"").Append(destinationPath).Append('\"');

I agree.

Let's remove cases with interpolated string and string concatenation from RCS1197.

josefpihrt avatar Jan 21 '24 17:01 josefpihrt