Skip to content

Commit

Permalink
Updated SA1008 to handle tuples in logical patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhellander committed Apr 26, 2022
1 parent 9c5d064 commit 7490969
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,23 @@ void Method(int b)
FixedCode = fixedCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3476, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3476")]
public async Task TestLogicalTuplePatternAsync()
{
const string testCode = @"
class C
{
void Method((int, int) c)
{
_ = c is (1, 1) or (2, 2);
_ = c is (1, 1) and (1, 1);
_ = c is not (2, 2);
}
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
3 changes: 3 additions & 0 deletions StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ internal static class SyntaxKindEx
{
public const SyntaxKind DotDotToken = (SyntaxKind)8222;
public const SyntaxKind QuestionQuestionEqualsToken = (SyntaxKind)8284;
public const SyntaxKind OrKeyword = (SyntaxKind)8438;
public const SyntaxKind AndKeyword = (SyntaxKind)8439;
public const SyntaxKind NotKeyword = (SyntaxKind)8440;
public const SyntaxKind ManagedKeyword = (SyntaxKind)8445;
public const SyntaxKind UnmanagedKeyword = (SyntaxKind)8446;
public const SyntaxKind NullableKeyword = (SyntaxKind)8486;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt

case SyntaxKindEx.PositionalPatternClause:
haveLeadingSpace = prevToken.IsKind(SyntaxKind.IsKeyword)
|| prevToken.IsKind(SyntaxKindEx.OrKeyword)
|| prevToken.IsKind(SyntaxKindEx.AndKeyword)
|| prevToken.IsKind(SyntaxKindEx.NotKeyword)
|| prevToken.IsKind(SyntaxKind.CommaToken);
break;

Expand Down

0 comments on commit 7490969

Please sign in to comment.