Repository navigation
SA1201: fix all member ordering in one pass - #4277
Merged
Merged
Conversation
SA1201 Fix All now reorders the complete affected member list, since a move can create additional ordering violations between siblings. Preserve the existing diagnostic-only handling for the other ordering rules. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4277 +/- ##
=======================================
Coverage 97.62% 97.62%
=======================================
Files 1287 1287
Lines 138192 138258 +66
Branches 4518 4522 +4
=======================================
+ Hits 134909 134978 +69
+ Misses 2113 2110 -3
Partials 1170 1170 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The expanded traversal can incorrectly reorder incomplete members during Fix All.
1 open finding
What changed in this PR
Updates SA1201 Fix All to reorder affected sibling lists completely in one pass.
Changes:
- Tracks all siblings for SA1201 Fix All.
- Adds issue #1589 regression coverage.
- Reduces expected Fix All iterations to one.
| File | Description |
|---|---|
ElementOrderCodeFixProvider.cs |
Expands SA1201 Fix All processing. |
SA1201UnitTests.cs |
Adds regression and updates iteration expectations. |
SA1201CSharp9UnitTests.cs |
Updates record test iteration expectation. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+388
to
+394
| foreach (var sibling in memberDeclaration.Parent.ChildNodes().OfType<MemberDeclarationSyntax>()) | ||
| { | ||
| if (trackedMembersSet.Add(sibling)) | ||
| { | ||
| trackedMembers.Add(sibling); | ||
| } | ||
| } |
This was referenced Nov 11, 2026
Bump StyleCop.Analyzers from 1.2.0-beta.556 to 1.3.180
microsoftgraph/aspnetcore-webhooks-sample#436
Open
Closed
Open
This was referenced Nov 23, 2026
Open
Open
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 #1589
SA1201 Fix All originally updated only members reported by the initial analysis. Moving those members can create a new ordering violation between siblings, leaving the affected type incomplete after one Fix All action.
The fix visits all direct siblings for affected SA1201 member lists, applying the existing safe member-move logic once per sibling. Fix All behavior for the other ordering diagnostics remains unchanged. A regression test uses the issue's sample and requires the complete order after one Fix All iteration; existing SA1201 class, struct, and C# 9 tests now also verify completion in one iteration.
The regression test fails on master in the Fix All in document check: Property3 remains after Method1, so the list is not fully ordered after one application.
Performance: analyzer behavior is unchanged. The additional work runs only when a user explicitly invokes SA1201 Fix All, and only for siblings in affected member lists.
Behavior change: SA1201 Fix All now reorders the full affected member list so violations introduced by earlier moves are corrected in the same action. Existing safeguards for field dependencies and directive boundaries remain in use.