Skip to content

SA1316: always check explicit element names in tuple expressions - #4202

Merged
AArnott merged 1 commit into
masterfrom
fix-3947-sa1316-explicit-tuple-names
Oct 9, 2026
Merged

AArnott merged 1 commit into
masterfrom
fix-3947-sa1316-explicit-tuple-names

Conversation

@AArnott

@AArnott AArnott commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #3947

SA1316 skipped tuple expressions entirely unless includeInferredTupleElementNames was true. So an explicitly named element like var tuple = (x: 1, Y: 2); was never checked by default, even though the setting is documented as covering only inferred names. With the setting on, explicit names were reported at the value expression and had no code fix.

HandleTupleExpressionAction now:

  • always checks explicit NameColon names (C# 7.0+), reporting on the name with the existing rename code fix
  • checks inferred names only when includeInferredTupleElementNames is on (C# 7.1+), as before

Behavior change: projects with mis-cased explicit names in tuple expressions will get new SA1316 warnings by default. I think this matches the documented intent of the setting, but it's the one part of this PR worth a conscious OK. Perf: the tuple-expression callback was already registered. It now loops over the arguments by default and does no semantic-model work for these names, so the extra cost is negligible.

Tests (C# 7 project, inherited by later versions): ValidateImproperCasedExplicitTupleExpressionElementNamesAsync runs all 7 settings variants and checks diagnostics on the names plus the code fix (including comments around the name and a _ element). All 7 fail on master. Existing SA1316 tests pass unchanged.

Docs: SA1316.md describes the explicit/inferred split, and the includeInferredTupleElementNames row in Configuration.md notes that explicit names are always analyzed.

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.54%. Comparing base (868775d) to head (f605e70).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4202   +/-   ##
=======================================
  Coverage   97.54%   97.54%           
=======================================
  Files        1277     1277           
  Lines      134157   134193   +36     
  Branches     4291     4292    +1     
=======================================
+ Hits       130863   130901   +38     
+ Misses       2152     2151    -1     
+ Partials     1142     1141    -1     
🚀 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:38
@AArnott
AArnott merged commit aa9d9e5 into master Oct 9, 2026
25 checks passed
@AArnott
AArnott deleted the fix-3947-sa1316-explicit-tuple-names branch October 9, 2026 17:17
This was referenced Nov 11, 2026
This was referenced Nov 13, 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.

SA1316 (Tuple element names should use correct casing) is not always triggered for incorrectly cased explicit member names

2 participants