Skip to content

SA1201: fix all member ordering in one pass - #4277

Merged
AArnott merged 1 commit into
masterfrom
aarnott-sa1201-fix-all-iterations
Oct 13, 2026
Merged

AArnott merged 1 commit into
masterfrom
aarnott-sa1201-fix-all-iterations

Conversation

@AArnott

@AArnott AArnott commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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.

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

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.62%. Comparing base (ed0ca0a) to head (38df84d).
⚠️ Report is 2 commits behind head on master.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AArnott
AArnott marked this pull request as ready for review October 13, 2026 17:56
Copilot AI balanced review requested due to automatic review settings October 13, 2026 17:56
@AArnott
AArnott merged commit 190bfae into master Oct 13, 2026
30 checks passed
@AArnott
AArnott deleted the aarnott-sa1201-fix-all-iterations branch October 13, 2026 17:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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
This was referenced Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SA1201 code fix needs to be executed multiple times

2 participants