-
Notifications
You must be signed in to change notification settings - Fork 16
fix: Add unit tests and improve analyzers for handling generated code and diagnostics #399
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,11 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context) | |
| { | ||
| ISymbol namedTypeSymbol = context.Symbol; | ||
|
|
||
| // ignore GeneratedCodeAttribute on field and first containing type | ||
| INamedTypeSymbol generatedCodeAttribute = context.Compilation | ||
| .GetTypeByMetadataName("System.CodeDom.Compiler.GeneratedCodeAttribute"); | ||
| ImmutableArray<AttributeData> attributes = namedTypeSymbol.GetAttributes().AddRange(namedTypeSymbol.ContainingType.GetAttributes()); | ||
| if (attributes.Any(attribute => attribute.AttributeClass?.Name == nameof(System.CodeDom.Compiler.GeneratedCodeAttribute))) | ||
| if (generatedCodeAttribute is not null && | ||
| attributes.Any(attribute => SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, generatedCodeAttribute))) | ||
|
Comment on lines
+42
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check seems like something that would make for a good extension method to saves repeating it. |
||
| { | ||
| return; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ namespace IntelliTect.Analyzer | |
| public static class DiagnosticUrlBuilder | ||
| { | ||
| private const string BaseUrl = "https://github.com/IntelliTect/CodingGuidelines"; | ||
| private static readonly Regex _HyphenateRegex = new(@"\s+", RegexOptions.Compiled); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we able to use the source generator for Regex here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No - because we are targeting netstandard 2.0 - unless there is a way to shim that back that I don't know of |
||
|
|
||
| /// <summary> | ||
| /// Get the full diagnostic help url | ||
|
|
@@ -21,8 +22,7 @@ public static string GetUrl(string title, string diagnosticId) | |
| if (string.IsNullOrWhiteSpace(diagnosticId)) | ||
| throw new System.ArgumentException("diagnostic ID cannot be empty", nameof(diagnosticId)); | ||
|
|
||
| Regex hyphenateRegex = new Regex(@"\s"); | ||
| string hyphenatedTitle = hyphenateRegex.Replace(title, "-"); | ||
| string hyphenatedTitle = _HyphenateRegex.Replace(title, "-"); | ||
|
|
||
| return BaseUrl + $"#{diagnosticId.ToUpperInvariant()}" + $"---{hyphenatedTitle.ToUpperInvariant()}"; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is there a reason we can't use multi-line string literals for these tests?