dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.92k stars 4.02k forks source link

Diagnostic for invalid String.Format expressions #15856

Open kuhlenh opened 7 years ago

kuhlenh commented 7 years ago

Make an analyzer to identify invalid String.Format expressions, e.g.:

String.Format("asdf {1} asdf", x.y);

This could help with #15758 in the future...(@pilchie and I were talking about this earlier today)

AdamSpeight2008 commented 7 years ago

I've already implemented this @kuhlenh, have a look at StringFormatDiagnostic. It does needs updating to work with the latest release of VS, any help would be appreciated. As it does (yet) provide code fixes for the issues.

Original Repo Repo for latest implementation FSDv2 (Note this is the core parser of the analyser).

In theory it could be extend to include Interpolation String, if it the parser aspect of the analyser could also understand identifiers, in the argument holes.