dotnet / format

Home for the dotnet-format command
MIT License
1.92k stars 174 forks source link

Support for DiagnosticSuppressors #1998

Open WhippetsAintDogs opened 10 months ago

WhippetsAintDogs commented 10 months ago

Running dotnet format on a project with 3rd-party analyzers doesn't seem to take DiagnosticSuppressors like those shipped with Microsoft.Unity.Analyzers into consideration.

Am I wrong? Is there any documentation on how to make that work or it's simply not supported yet? If so, any plans to support these?

Thank you!

corngood commented 9 months ago

Here's what I've found:

                    var severity = await analyzer.GetSeverityAsync(project, formattablePaths, cancellationToken).ConfigureAwait(false);
                    if (severity >= minimumSeverity)
                    {
                        analyzers.Add(analyzer);
                    }

My fix for that is https://github.com/corngood/format/commit/fa99c154fe3933d13ad5f788b0e6176121c002cd

We treat suppressors separately and use them unconditionally if they may suppress any of the diagnostics that have been referenced by the other analysers.

I only have a hack for this: https://github.com/corngood/format/commit/89fff8446f38ee1021a4adb131ddb106c938b60a

You have CodeStyleFormatter and ThirdPartyFormatter, which are run separately, so suppressors in the latter (e.g. ones referenced in a .csproj) aren't aware of diagnostics from the former.

My hack combines the passes together, and I am now able to suppress style diagnostics.

IMO To get this to a PR, that second change needs to be cleaned up, and we need tests.