Respect object initializer severity for fade diagnostics#84324
Merged
333fred merged 1 commit intoJul 1, 2026
Conversation
717e128 to
b6bff64
Compare
b6bff64 to
79a74d4
Compare
333fred
commented
Jun 30, 2026
| .WithLocation(0) | ||
| .WithOptions(DiagnosticOptions.IgnoreAdditionalLocations), | ||
| VerifyCS.Diagnostic("IDE0017") | ||
| .WithSeverity(DiagnosticSeverity.Info) |
Member
Author
There was a problem hiding this comment.
Note: verifying the severity of the diagnostics is important here, as the bug is that these diagnostics had different severities. If there's a better way to do this in the IDE side of the codebase, please let me know.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the C# “Use object initializer” analyzer so the fade-out (unnecessary-code) diagnostics use the configured dotnet_style_object_initializer notification severity, and adds regression coverage for severity precedence between per-option configuration and bulk Style category configuration.
Changes:
- Pass the code-style option’s notification setting through when reporting object-initializer fade diagnostics.
- Update an existing severity-configuration test to assert explicit severities (and ignore additional locations).
- Add a new regression test ensuring
dotnet_style_object_initializer = true:suggestionis not overridden bydotnet_analyzer_diagnostic.category-Style.severity = warningfor IDE0017.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Analyzers/Core/Analyzers/UseObjectInitializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs | Changes fade-out diagnostic reporting to use the option’s notification severity. |
| src/Analyzers/CSharp/Tests/UseObjectInitializer/UseObjectInitializerTests.cs | Adds/updates tests covering severity precedence and explicit expected severities for IDE0017 diagnostics. |
Member
Author
|
@dotnet/roslyn-ide for a review please |
JoeRobich
approved these changes
Jun 30, 2026
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.
Summary
dotnet_style_object_initializernotification severity to object-initializer fade diagnostics.dotnet_style_object_initializer = true:suggestioncoexists withdotnet_analyzer_diagnostic.category-Style.severity = warning, ensuring both IDE0017 diagnostics remain info/suggestion severity.Microsoft Reviewers: Open in CodeFlow