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.91k stars 4.01k forks source link

Enhance compiler's SARIF errorlog to emit containing symbol information for each reported diagnostic #42489

Open mavasani opened 4 years ago

mavasani commented 4 years ago

Extracted out from https://github.com/dotnet/roslyn/issues/32102

Context

We have got lot of internal feature requests where a team wants to enable new analyzer package on their repo, and wants to generate a baseline of all the existing analyzer violations using a custom command line tool. The current baselining support in Visual Studio only works on individual projects/solutions and also needs the build administrator to open each solution in Visual Studio and manually perform a baseline operation. This is not feasible for big repos, especially as they keep adding new analyzer packages and/or move to new version of analyzer packages and want to repeat the baseline operation. Hence, the request is to provide richer symbolic information for diagnostics in SARIF errorlog output of the compiler, so that they can author a custom command line tool that operates directly off this error log output to generate global SuppressMessage attributes in a suppressions file which can suppress each of the reported diagnostics.

Compiler Feature Request

Enhance the /errorlog command line switch (or provide a new command line switch) so that the SARIF output contains the following additional information for each reported diagnostic:

  1. Symbol kind of the containing symbol of the diagnostic location
  2. Documentation Comment ID of the containing symbol of the diagnostic location

Above information can be easily mapped to the target string and scope for suppress message attributes that can suppress corresponding diagnostic instance.

paulomorgado commented 4 years ago

I have a tool consuming the SARIF that needs, for each result (error/warning):

I had to build analyzers to produce this information. It would be great to have it out of the box.