roslynator
roslynator copied to clipboard
RCS0055 doesn't know how to deal with concatenated strings as arguments
Product and Version Used: 3.2.0
Steps to Reproduce:
-
Create a new console project using .NET 5
-
Install Roslynator.Analyzers
-
Create an
.editorconfigwith the following contents[*.cs] dotnet_diagnostic.RCS0055.severity = error -
Update your Program.cs as follows
using System; namespace RoslynatorProblem { internal static class Program { internal static void Main() { Console.WriteLine( "some text " + "some more text"); } } }
Actual Behavior:
RCS0055 is raised for fix formatting of a binary expression chain on the line where the string is defined in the Console.WriteLine call.
Expected Behavior:
I believe this should not cause an error, or perhaps there can be some guidance in the docs for how one should deal with this particular situation. I'm uncertain if there's a way to solve this or if it's a bug.
I would like to clarify what you are suggesting: Do you want not to indent string concatentation or any "add expression" or anything else?
I'd like to sincerely apologise for missing your reply and question. The reason that one may choose to concatenate strings like this is when enforcing a line limit and the string is very long.
As you can see here, using + is more performant than using something like string.Concat.
Please let me know your thoughts 😄 Fotis
I think this issue need more clarification.
Are you suggesting not to indent "add operator" on multiple lines if the "add operator" is actually string concatenation?
Current behavior
Code with diagnostic
Console.WriteLine(
"first"
+ "second"
+ "third");
Code with fix:
Console.WriteLine(
"first"
+ "second"
+ "third");
Proposed behavior
Code with no diagnostic:
Console.WriteLine(
"first"
+ "second"
+ "third");
Code with diagnostic (not string concatenation):
Console.WriteLine(
1
+ 2
+ 3);
I think this issue need more clarification.
Are you suggesting not to indent "add operator" on multiple lines if the "add operator" is actually string concatenation?
Current behavior
Code with diagnostic
Console.WriteLine( "first" + "second" + "third");Code with fix:
Console.WriteLine( "first" + "second" + "third");Proposed behavior
Code with no diagnostic:
Console.WriteLine( "first" + "second" + "third");Code with diagnostic (not string concatenation):
Console.WriteLine( 1 + 2 + 3);
Thanks for the reply. Actually your post answers my original question. I think it may be worth explaining what the required fix is in the docs for such an example as I couldn't quite figure out what Rsolynator is after using the docs.
Now that I see your solution, I agree with what Roslynator is suggesting. Having the subsequent lines indented creates a visual distincition between those and other method arguments.
So my only suggestion out of this ticket would be to maybe update the docs with the examples you showed above too.
I'm happy to close the ticket if you're happy too.
Huge love and thanks! Fotis
I think it's safe to close this one now 😄