Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated SA1008 to handle tuples in logical patterns #3495

Merged
merged 1 commit into from May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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