Skip to content

SA1202: Order explicit interface events as public - #4281

Merged
AArnott merged 3 commits into
masterfrom
aarnott-explicit-event-ordering
Oct 13, 2026
Merged

AArnott merged 3 commits into
masterfrom
aarnott-explicit-event-ordering

Conversation

@AArnott

@AArnott AArnott commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #1823

Explicit interface events were omitted from MemberOrderHelper.GetAccessLevelForOrdering, while explicit methods, properties, and indexers are treated as public. This caused SA1202 to report an already correctly ordered explicit event before a public event, and accessibility-first SA1201 configurations to skip event ordering.

The shared helper now treats only explicit event declarations as public. Tests cover the issue's exact false positive, reordering and the SA1202 code fix, a non-explicit event near miss, and an accessibility-first SA1201 configuration. All three new regression cases fail on master: the issue case reports SA1202 at the public event, while the explicit-event code-fix and SA1201 cases produce no diagnostic. documentation/SA1202.md now states the behavior.

⚑ StyleCop Classic treated explicit interface events as private. This intentionally deviates from Classic and aligns events with the other explicit interface members, as agreed in the issue discussion.

Performance: the change adds one SyntaxKind check to shared access classification; it adds no callbacks, allocations, or semantic-model work. In a no-event edit simulation (StyleCopTester.exe /id:SA1202 /editperf:MemberOrderHelper.cs /edititer:100 /force StyleCopAnalyzers.slnx, three runs on master and three after the change), median throughput was 8.79 vs. 7.50 edits/sec, with overlapping run ranges of 7.48–10.29 and 7.49–8.28 edits/sec. The variation is larger than the measured difference; no regression was measurable.

Validation:

  • dotnet build StyleCopAnalyzers.slnx -c Debug — 0 warnings, 0 errors.
  • C# 6 SA1201/SA1202 tests — 86 passed; SA1204/SA1214 — 36 passed.
  • dotnet test test/StyleCop.Analyzers.Test.CSharp15 --no-build -f net10.0 --filter "FullyQualifiedName~OrderingRules" — 742 passed.

Align event ordering with explicit methods, properties, and indexers; cover diagnostic, code-fix, and accessibility-first configuration behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AArnott
AArnott marked this pull request as ready for review October 13, 2026 18:33
Copilot AI balanced review requested due to automatic review settings October 13, 2026 18:33

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 resulting SA1204 behavior needs a dedicated regression test.

1 open finding
What changed in this PR

Aligns explicit interface events with other explicitly implemented members by treating them as public for ordering.

Changes:

  • Updates shared accessibility classification.
  • Adds SA1201/SA1202 regression and code-fix tests.
  • Documents the intentional StyleCop Classic deviation.
File Description
MemberOrderHelper.cs Classifies explicit interface events as public.
SA1201UnitTests.cs Tests accessibility-first ordering.
SA1202UnitTests.cs Tests diagnostics, fixes, and near misses.
SA1202.md Documents event ordering behavior.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Cover SA1204's use of explicit event accessibility when ordering static members.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 18:40

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.

🔵 Needs a closer look

The corresponding Russian and Czech documentation editions must be synchronized with the English update.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity Update Russian and Czech SA1202 documentation with behavior note

documentation/​SA1202.md:39

The Russian and Czech SA1202.md editions were not updated with this clarification, so those published editions omit the newly documented StyleCop Classic deviation. CONTRIBUTING.md:114-116 requires all editions to stay current because localized Markdown has no English fallback; please update both localized pages with the same behavior note.

🧠 Review effort: Balanced

Keep the Czech and Russian rule descriptions aligned with the explicit-event ordering behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 18:54

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.

🟢 Approval recommended

The focused helper change is documented and adequately covered across all affected ordering rules.

0 open findings

🧠 Review effort: Balanced

@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.63%. Comparing base (dfaef0c) to head (e841a9a).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #4281    +/-   ##
========================================
  Coverage   97.63%   97.63%            
========================================
  Files        1287     1287            
  Lines      138447   138563   +116     
  Branches     4529     4529            
========================================
+ Hits       135171   135290   +119     
+ Misses       2108     2102     -6     
- Partials     1168     1171     +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This was referenced Nov 22, 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.

MemberOrderHelper.GetAccessLevelForOrdering does not consider explicit event implementations

2 participants