dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.
https://josefpihrt.github.io/docs/roslynator
Other
3.05k stars 254 forks source link

Lack of symmetry in refactorings vs analyzers #327

Open IanKemp opened 6 years ago

IanKemp commented 6 years ago

For refactorings, we have both RR0168 Use "" instead of string.Empty and its inverse RR0171, Use string.Empty instead of "".

But for analyzers, we have RCS1078, Use "" instead of string.Empty which corresponds with RR0168, but no corresponding analyzer for RR0171. This seems like an omission.

Also, I'm confused why RR0168 is enabled by default whereas RR0171 is disabled - to my mind it should be the other way around, as using a readonly field is always safer than a literal. Is this simply a coding style choice on your part?

josefpihrt commented 6 years ago

I think that I tried to develop analyzer 'Use string.Empty instead of ""' but it turned out that it is quite tricky do detect if string.Empty (read-only field) can replace empty string (constant) so I gave it up.