Skip to content

Commit 9f28a3b

Browse files
author
Zhang Shen
committed
SA1316: allow discards in tuple
1 parent dc163bf commit 9f28a3b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/NamingRules/SA1316CSharp7UnitTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,5 +346,22 @@ public void MethodName(List<(string Name, string Value)> list)
346346

347347
await VerifyCSharpDiagnosticAsync(languageVersion: null, testCode, PascalCaseTestSettings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
348348
}
349+
350+
[Fact]
351+
[WorkItem(3139, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3139")]
352+
public async Task TestTupleDesconstructionDiscardAsync()
353+
{
354+
var testCode = @"
355+
public class TypeName
356+
{
357+
public void MethodName((string Name, string Value) obj)
358+
{
359+
(string name, _) = obj;
360+
}
361+
}
362+
";
363+
364+
await VerifyCSharpDiagnosticAsync(LanguageVersionEx.CSharp7, testCode, DefaultTestSettings, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
365+
}
349366
}
350367
}

StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ private static void CheckTupleElement(SyntaxNodeAnalysisContext context, StyleCo
106106

107107
private static void CheckName(SyntaxNodeAnalysisContext context, StyleCopSettings settings, string tupleElementName, Location location, bool prepareCodeFix)
108108
{
109+
if (tupleElementName == "_")
110+
{
111+
return;
112+
}
113+
109114
var firstCharacterIsLower = char.IsLower(tupleElementName[0]);
110115

111116
bool reportDiagnostic;

0 commit comments

Comments
 (0)