-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add overload to Diagnostic Analyzer template to support extra MetadataReferences #2369
Comments
Yes, I have run into this too. And patched the template code likewise. Besides this, additional metadata references should be supported in the CodeFixVerifier. |
Something else that would be nice: being able to specify a custom file name for running the analyzer and fix provider. I'm working on an analyzer that skips generated code files like Form1.Designer.cs. Such files are generated by VS without |
@bkoelman In the StyleCopAnalyzers project, we don't look for |
@sharwell Good to know about performance, will keep that in mind. Interesting to scan comments at top-of-file also. That pull request does not contain unit tests though. Wouldn't you need my request for that? |
@bkoelman I don't think I understood your question. Can you rephrase it? |
@sharwell Correct me if I've missed something, but the StyleCop source seems to contain checks based on comment and filename ( Furthermore, I see a unittest that verifies comments (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/aa3d45dd97e72e3d15dcd4ac62cf16145cc31e60/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs), but not one that verifies behavior based on filename. Just like I did, you would need to replace/rewrite parts of the generated template code for namespace TestHelper
{
public abstract partial class DiagnosticVerifier
{
private static Document[] GetDocuments(string[] sources, string language)
{
// ...
for (int i = 0; i < sources.Length; i++)
{
string fileName = language == LanguageNames.CSharp ? "Test" + i + ".cs" : "Test" + i + ".vb";
} So my question is: how would you write that missing unit test? To me it seems you are missing the same feature (filename support) that I am missing currently in the generated template code. |
I am wondering whether this issue is still relevant with the new test framework? |
@sharwell Is this still relevant? If it's, I think it will belong to roslyn-sdk repository. |
My team has been writing some Roslyn diagnostic analyzers and all the new developers on our team have encountered this situation, so I thought I'd bring up this suggestion.
The Roslyn analyzers template auto-generates a test project along with verifiers. By default, they only compile the test source code with 4 assemblies (ie. mscorlib, System.Core, etc).
We found ourselves in a situation where any symbols returned from the SyntaxTree is
null
and we were not sure why because the logic in the analyser looked good. We realised thenull
was because it wasn’t able to compile the test source code that we were using due to references from other assemblies likeComposablePartsCatalog
inSystem.Composition.ComponentModel.dll
.We had to add an overload to DiagnosticVerifier.Helper.cs to accept more metadata references.
I think any developer who wants to use a class other than those 4 will find themselves confused and spend time debugging just to come to the same conclusion as we did.
This is the code we added to the existing template code in
DiagnosticVerifier.Helper.cs
.The text was updated successfully, but these errors were encountered: