format
format copied to clipboard
Support for DiagnosticSuppressors
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!
Here's what I've found:
- suppressors don't get run reliably because of this block:
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.
- analysers and 'style' stuff are not run in the same pass
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.