Skip to content

SA1604: honor private documentation settings for excluded declarations - #4274

Merged
AArnott merged 1 commit into
masterfrom
aarnott-sa1604-exclude
Oct 13, 2026
Merged

AArnott merged 1 commit into
masterfrom
aarnott-sa1604-exclude

Conversation

@AArnott

@AArnott AArnott commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #3094

Treat declarations with a top-level <exclude/> as private for SA1604, following the maintainer guidance in #3121, rather than disabling all documentation checks. Missing summaries remain diagnostics when documentPrivateElements is enabled, or documentPrivateFields for fields. Exclude tags are recognized both directly and through expanded <include> documentation. Nested <exclude/> and differently cased <Exclude/> do not suppress diagnostics.

This PR is intentionally limited to SA1604. The shared summary base passes its already-cached settings through to the handler; SA1606 behavior is unchanged. English, Czech, and Russian rule documentation describes the behavior (localized wording has not received native-speaker review).

Regression and validation

The exact reported example was added first to the C# 6 SA1604 suite. The test fails on master 5fb0ffaf999434bf5b78b7c8bb86c8334ac46b37, before any product edits: expected 0 diagnostics, actual 1, SA1604: Element documentation should have summary at line 2, column 14. It passes with this change.

Added 42 cases covering declaration kinds, both settings outcomes, independent private-field/private-element settings, multiple field/event locations, valid summaries, near misses, and inline/included exclude tags.

  • SDK: 10.0.401 from global.json.
  • dotnet build -c Release -maxcpucount:1: succeeded, 0 warnings, 0 errors.
  • Focused SA1604 + SA1606 suites: 1,890 passing across C# 6–15 on net10.0 Release; 373 passing in the oldest/newest projects on net472 Release; 163 passing in the C# 6 project on net10.0 Debug. No failures or skipped tests.
  • Filter: FullyQualifiedName~SA1604|FullyQualifiedName~SA1606.
  • git diff --check passes; generated files are unchanged.

Analyzer cost

No new registrations, semantic-model calls, symbol walks, reflection, or caches. Existing cached settings are passed through. The new work occurs only after the existing summary/inheritdoc and documentation-required checks would otherwise report SA1604: a private-setting check and a top-level exclude lookup. Declarations without documentation or with summaries retain their existing early exits. The lookup uses the existing XML helper and incurs its iterator/name-string costs on missing-summary comments; includes reuse the already-expanded XML.

A local synthetic comparison used the master and fixed Debug analyzer DLLs with Roslyn 5.0.0 and .NET 10, single-threaded CompilationWithAnalyzers, 2,000 public classes per corpus, 5 warmups + 20 measured iterations per process, three baseline/fixed process pairs. Medians of the three per-process analyzer-time medians:

Documentation Master Fixed Diagnostic count (master → fixed)
<summary>Summary.</summary> 8.107 ms 10.080 ms 0 → 0
<remarks>Remark.</remarks> 14.695 ms 16.265 ms 2,000 → 2,000
<exclude/> 14.223 ms 3.982 ms 2,000 → 0

Passing-summary timings were noisy (master 7.636–8.948 ms; fixed 4.937–14.174 ms), so these are not a throughput guarantee. On the deliberately all-missing-summary remarks corpus, the measured increase was about 1.57 ms per 2,000 declarations (0.8 μs each). Whole-driver allocation medians were 19,480,232 → 19,787,040 bytes for remarks and 18,494,624 → 17,214,096 bytes for exclude. These include Roslyn allocations and are not per-rule allocation accounting.

To reproduce the comparison: preserve the master Debug DLL, build the fixed Debug DLL, load each explicitly in a separate process, parse 2,000 unique public classes whose documentation is one of the three rows above using DocumentationMode.Diagnose, reuse the compilation but create a fresh analyzer driver for each iteration with concurrentAnalysis: false and logAnalyzerExecutionTime: true, and collect GetAnalyzerTelemetryInfoAsync(...).ExecutionTime after five warmups. The expected common-path cost is only forwarding the existing settings reference; the additional syntax lookup is confined to comments that would otherwise be diagnosed.

Honor private-element and private-field documentation settings instead of unconditionally suppressing summary checks. Add the exact #3094 regression and near-miss, settings, declaration, and include coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AArnott
AArnott marked this pull request as ready for review October 13, 2026 16:02
Copilot AI balanced review requested due to automatic review settings October 13, 2026 16:02
@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.61%. Comparing base (5fb0ffa) to head (cb77534).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4274   +/-   ##
=======================================
  Coverage   97.61%   97.61%           
=======================================
  Files        1285     1285           
  Lines      137307   137401   +94     
  Branches     4451     4462   +11     
=======================================
+ Hits       134029   134123   +94     
  Misses       2113     2113           
  Partials     1165     1165           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AArnott
AArnott merged commit e0563f8 into master Oct 13, 2026
30 checks passed
@AArnott
AArnott deleted the aarnott-sa1604-exclude branch October 13, 2026 16:03

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

Interface settings can bypass the new private-documentation behavior for excluded declarations.

1 open finding
What changed in this PR

Updates SA1604 so top-level <exclude/> declarations follow private-documentation settings.

Changes:

  • Adds direct and included <exclude/> handling.
  • Passes cached settings through the shared summary analyzer.
  • Adds regression tests and localized documentation.
File Description
test/​.../​SA1604UnitTests.cs Adds regression and settings tests.
src/​.../​XmlCommentHelper.cs Defines the exclude tag constant.
src/​.../​SA1606ElementDocumentationMustHaveSummaryText.cs Adopts the updated handler signature.
src/​.../​SA1604ElementDocumentationMustHaveSummary.cs Implements exclude handling.
src/​.../​ElementDocumentationSummaryBase.cs Passes settings to summary handlers.
documentation/​SA1604.md Documents the new behavior.
documentation/​ru-ru/​SA1604.md Adds Russian documentation.
documentation/​cs-cz/​SA1604.md Adds Czech documentation.

🧠 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 +83 to +85
bool documentPrivate = context.Node.IsKind(SyntaxKind.FieldDeclaration)
? settings.DocumentationRules.DocumentPrivateFields
: settings.DocumentationRules.DocumentPrivateElements;
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.

Documentation rules should not be checked if an <exclude/> tag is present

2 participants