Skip to content

Respect object initializer severity for fade diagnostics#84324

Merged
333fred merged 1 commit into
dotnet:mainfrom
333fred:ide0017-object-initializer-severity-fix
Jul 1, 2026
Merged

Respect object initializer severity for fade diagnostics#84324
333fred merged 1 commit into
dotnet:mainfrom
333fred:ide0017-object-initializer-severity-fix

Conversation

@333fred

@333fred 333fred commented Jun 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Pass the configured dotnet_style_object_initializer notification severity to object-initializer fade diagnostics.
  • Add a regression test where dotnet_style_object_initializer = true:suggestion coexists with dotnet_analyzer_diagnostic.category-Style.severity = warning, ensuring both IDE0017 diagnostics remain info/suggestion severity.
Microsoft Reviewers: Open in CodeFlow
@333fred 333fred force-pushed the ide0017-object-initializer-severity-fix branch from 717e128 to b6bff64 Compare June 29, 2026 20:03
@333fred 333fred force-pushed the ide0017-object-initializer-severity-fix branch from b6bff64 to 79a74d4 Compare June 29, 2026 22:58
@333fred 333fred marked this pull request as ready for review June 30, 2026 16:33
@333fred 333fred requested a review from a team as a code owner June 30, 2026 16:33
Copilot AI review requested due to automatic review settings June 30, 2026 16:33
.WithLocation(0)
.WithOptions(DiagnosticOptions.IgnoreAdditionalLocations),
VerifyCS.Diagnostic("IDE0017")
.WithSeverity(DiagnosticSeverity.Info)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:suggestion is not overridden by dotnet_analyzer_diagnostic.category-Style.severity = warning for 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.
@333fred

333fred commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

@dotnet/roslyn-ide for a review please

@333fred 333fred merged commit 964bb7d into dotnet:main Jul 1, 2026
25 checks passed
@333fred 333fred deleted the ide0017-object-initializer-severity-fix branch July 1, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants