Fix MAS0004 stopping at the first unrelated CA1507 diagnostic - #1340
Merged
Merged
Conversation
ReportSuppressions iterated context.ReportedDiagnostics but used return instead of continue for the three "not applicable" cases. Since ReportedDiagnostics contains every CA1507 of the compilation and most of them are not inside an attribute, the loop exited before ever reaching the [Newtonsoft.Json.JsonProperty] one, making the suppressor effectively non-functional in any real project. Also hoist the GetBestTypeByMetadataName lookup out of the loop and bail early when Newtonsoft.Json is not referenced. Add a test with two CA1507 diagnostics in one file, the attribute one second, which reproduces the bug. Fixes #1337
Only look up Newtonsoft.Json.JsonPropertyAttribute once a CA1507 diagnostic is actually located inside an attribute, so compilations without such a diagnostic never load the symbol.
meziantou
enabled auto-merge (squash)
August 26, 2026 18:14
This was referenced Aug 26, 2026
Closed
Bump Meziantou.Analyzer from 3.0.103 to 3.0.182
Analogy-LogViewer/Analogy.LogViewer.OpenTelemetry#98
Closed
Closed
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.189
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#556
Closed
This was referenced Sep 21, 2026
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.270
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#581
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.270
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#562
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
chore(deps): Bump the nuget-minor-and-patch group with 2 updates
donislawdev/BetterWindowsServices#3
Merged
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1337
What changed
CA1507SerializationPropertyNameSuppressor.ReportSuppressionsiteratescontext.ReportedDiagnostics, but the three "not applicable" guards usedreturninstead ofcontinue.ReportedDiagnosticscontains every CA1507 of the compilation, and the vast majority are not inside an attribute — sonode.FirstAncestorOrSelf<AttributeSyntax>()was null and the method exited before ever reaching the[Newtonsoft.Json.JsonProperty]one. MAS0004 was effectively non-functional in any real project, and whether it worked at all depended on the ordering ofReportedDiagnostics, which is not guaranteed.returnstatements are nowcontinue.GetBestTypeByMetadataName("Newtonsoft.Json.JsonPropertyAttribute")is hoisted out of the loop, with an early bail when Newtonsoft.Json is not referenced.Test
CA1507_NewtonsoftJson_JsonPropertyName_AfterAnUnrelatedDiagnosticputs two CA1507 diagnostics in one file with the attribute one second: the first stays reported, the second must be suppressed. The three existing tests each contained exactly one CA1507, which is why the bug was invisible to the suite.Notes for reviewers
"Bar") and to pass with the fix.#if ROSLYN_4_10_OR_GREATER, which is pre-existing.dotnet run --project src/DocumentationGeneratorexits 0 with no markdown changes.CA1822DecoratedMethodSuppressordelegates the per-diagnostic work to a helper method, andIDE0058Suppressoralready usescontinue.