Skip to content

Fix Blazor [Parameter] public code fix handling of multiple access modifiers#67365

Merged
dariatiurina merged 4 commits into
dotnet:mainfrom
damyanpetev:dpetev/blazor-param-code-fix
Jun 25, 2026
Merged

Fix Blazor [Parameter] public code fix handling of multiple access modifiers#67365
dariatiurina merged 4 commits into
dotnet:mainfrom
damyanpetev:dpetev/blazor-param-code-fix

Conversation

@damyanpetev

Copy link
Copy Markdown
Contributor

Fix Blazor [Parameter] public code fix handling of multiple access modifiers

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Changed to logic to rebuild the newModifiers collection with .Add() and filtering out existing access modifiers to avoid modification issues of the existing .Remove() use with more than one access modifier.

Description

ComponentParametersShouldBePublicCodeFixProvider was modifying the SyntaxTokenList while iterating, causing attempts to remove beyond the first to fail, leaving resulting code in wrong state with likely compiler errors.

The came from looking at the comment about private public protected int Foo { get; set; } which unfortunately, besides sitting on an IDE Modifiers are not orderedIDE0036 warning, is causing an More than one protection modifier CS0107 so I can't really get that scenario to even trigger the code fix. While it'll likely fix it fine, I've removed the comment since the refactored logic no longer needs the explanation.

Fixes #67364

…ifier handling

ComponentParametersShouldBePublicCodeFixProvider was modifying the SyntaxTokenList
while iterating, causing attempts to remove beyond the first to fail, leaving
resulting code in wrong state with likely compiler errors
Copilot AI review requested due to automatic review settings June 22, 2026 15:03
@damyanpetev damyanpetev requested a review from a team as a code owner June 22, 2026 15:03
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 22, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @damyanpetev. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

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 fixes the Blazor analyzer code fix (BL0004) that updates [Parameter] properties to public so it correctly handles members that have multiple access modifiers (e.g., private protected, protected internal) without leaving behind an extra access modifier that would produce invalid code.

Changes:

  • Reworked the code fix modifier rewrite logic to build a fresh SyntaxTokenList starting with public and then re-add only non-access modifiers.
  • Added regression tests covering valid multi-access-modifier cases and a mixed-modifier case (protected new internal) to ensure non-access modifiers are preserved.
  • Applied the same fix and tests in both the in-box analyzers and the SDK analyzers copies.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Components/Analyzers/src/ComponentParametersShouldBePublicCodeFixProvider.cs Rebuilds modifier list to remove all access modifiers and insert public reliably.
src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs Adds coverage for multi-access-modifier parameter properties and preservation of new.
src/Tools/SDK-Analyzers/Components/src/ComponentParametersShouldBePublicCodeFixProvider.cs Mirrors the same modifier list rebuild fix for the SDK analyzers variant.
src/Tools/SDK-Analyzers/Components/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs Mirrors the same multi-modifier regression tests for the SDK analyzers variant.

@dariatiurina dariatiurina 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.

This is amazing! Thank you so much for your work! 💕

@dariatiurina dariatiurina 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.

Reapply approve

@dariatiurina dariatiurina changed the title fix(blazor,analyzer): parameter attribute code fix multi-modifier handling Fix Blazor [Parameter] public code fix handling of multiple access modifiers Jun 25, 2026
@dariatiurina dariatiurina merged commit 6ad0de2 into dotnet:main Jun 25, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 26, 2026
@damyanpetev damyanpetev deleted the dpetev/blazor-param-code-fix branch June 26, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor analyzer public [Parameter] code fix fails to replace multiple modifiers

3 participants