Skip to content

SA1205: treat the C# 11 file modifier as an access modifier - #4198

Merged
AArnott merged 3 commits into
masterfrom
fix-3906-sa1205-file-partial
Oct 9, 2026
Merged

AArnott merged 3 commits into
masterfrom
fix-3906-sa1205-file-partial

Conversation

@AArnott

@AArnott AArnott commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #3906

SA1205 asked for an access modifier on file partial class, but file already is the type's accessibility, and adding public/internal would be a compile error (CS0106).

This builds on @bjornhellander's original draft commit 2e31c40 ("Update SA1205 to recognize the file keyword"), which treats SyntaxKindEx.FileKeyword as an access modifier. That commit was never opened as a PR. I merged current master into it and added:

  • more ValidDeclarations cases under SupportsCSharp11: file static/sealed partial class, file partial interface, file partial record, file partial record struct. These live in the C# 6 base class, so they run from the C# 11 test project onward. All 7 file cases fail on master.
  • a short "File-local types in C# 11" section in documentation/SA1205.md.

It's one more modifier check, so there's no perf cost.

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.54%. Comparing base (868775d) to head (9f1bf6d).
⚠️ Report is 14 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4198   +/-   ##
=======================================
  Coverage   97.54%   97.54%           
=======================================
  Files        1277     1277           
  Lines      134157   134168   +11     
  Branches     4291     4292    +1     
=======================================
+ Hits       130863   130875   +12     
+ Misses       2152     2151    -1     
  Partials     1142     1142           
🚀 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 9, 2026 15:20
yield return new object[] { "record struct" };
}

if (LightupHelpers.SupportsCSharp11)

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.

Codecov says this if statement is only partially covered. I don't see how that is possible, so might be worth a check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I suspect that's because the condition always evaluates to true. So the missing coverage is of the jmp that skips past the 'true' block.

@AArnott
AArnott merged commit dd0cbd6 into master Oct 9, 2026
25 checks passed
@AArnott
AArnott deleted the fix-3906-sa1205-file-partial branch October 9, 2026 17:29
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.

FP: SA1205 for partial, file-scoped classes

2 participants