roslyn-sdk icon indicating copy to clipboard operation
roslyn-sdk copied to clipboard

Feature proposal: Patternized Rule names

Open taori opened this issue 5 years ago • 3 comments

I was just writing a test when the test error output printed me the templates diagnostics like VerifierCS.ACA0004 and i thought that it could be a neat little sdk analyzer who helps you with making sure diagnostic id's do not conflict with each other at the same time as the generated output could be more precise in what it prints (since the DiagnosticDescriptor might have a different name)

Let's say the diagnostic searches the solution for an assembly attribute like [assembly:RuleIdPattern("ACA####")] and uses those patterns to verify uniqueness of the descriptor and provides the test assembly with information to provide the actual rule instead of an assumed one.

Right now i have got a static class DiagnosticIds but that seems like an odd solution and i haven't really checked out another project yet, to see how they manage id's since having multiple analyzers developed in different branches might lead to collisions at some point? (Idk, maybe there already is some underlying mechanism to guard from that)

taori avatar Jan 20 '20 17:01 taori

since the DiagnosticDescriptor might have a different name

We should use reflection to look at the static fields and properties of the analyzer to find the one that matches the one reported in a diagnostic. If none is found, we should look for a static field or property that has the correct diagnostic ID as a string.

sharwell avatar Jan 20 '20 21:01 sharwell

📝 The feature you refer to is actually very new. I added a rough initial version in #416 with hopes that we can iterate on it to improve accuracy.

sharwell avatar Jan 20 '20 21:01 sharwell

Oh i see. Great idea to implement this feature then. It's super useful and saves a lot of time.

I probably should have split this into two issues then though

  • compile time ensurance that diagnostic id's are unique in that assembly
  • improved copy&paste functiontionality for test output

taori avatar Jan 20 '20 22:01 taori