DotNetAnalyzers / StyleCopAnalyzers

An implementation of StyleCop rules using the .NET Compiler Platform
MIT License
2.61k stars 506 forks source link

New rule: don't use string interpolation $ without interpolation expression #3827

Closed urmel9 closed 1 month ago

urmel9 commented 2 months ago

Hey, it leads to confusion when you indicate with $ that the string uses String interpolation, but it doesn't. Therefore, I want to suggest a new rule: don't use string interpolation $ without interpolation expression For diagnostics you could check like this: IF string starts with $ THEN curly braces inside {} ELSE styleCop warning

WARNING: Console.WriteLine($"Hello World!");

sharwell commented 2 months ago

I've never observed or encountered any confusion related to these forms, so I lean against adding a rule to enforce one over the other. This is particularly true now that constant interpolated strings are treated as constants by the compiler, and thus have no penalty for use.

dmcnaughton-nbc commented 1 month ago

I agree with @sharwell on this, the biggest factor is that it's no longer a performance penalty. If there was a performance penalty, or even a potential for formatting issues, this would be a very useful rule.

urmel9 commented 1 month ago

@sharwell @dmcnaughton-nbc Okay, if there is no performance issue you can reject hat idea. Thanks!