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

Update SA1008 to handle positional patterns inside property patterns #3579

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,50 @@ await VerifyCSharpFixAsync(
fixedCode,
CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3556, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3556")]
public async Task TestInPositionalPatternAfterTagAsync()
{
var testCode = @"
internal class TestClass
{
private void TestMethod(object obj)
{
_ = obj is ClassWithTuple { Tag:{|#0:(|} true, false) };
}

public class ClassWithTuple
{
public (bool Item1, bool Item2) Tag { get; set; }
}
}
";
var fixedCode = @"
internal class TestClass
{
private void TestMethod(object obj)
{
_ = obj is ClassWithTuple { Tag: (true, false) };
}

public class ClassWithTuple
{
public (bool Item1, bool Item2) Tag { get; set; }
}
}
";
DiagnosticResult[] expectedResults =
{
Diagnostic(DescriptorPreceded).WithLocation(0),
Diagnostic(DescriptorNotFollowed).WithLocation(0),
};

await VerifyCSharpFixAsync(
testCode,
expectedResults,
fixedCode,
CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
|| prevToken.IsKind(SyntaxKindEx.OrKeyword)
|| prevToken.IsKind(SyntaxKindEx.AndKeyword)
|| prevToken.IsKind(SyntaxKindEx.NotKeyword)
|| prevToken.IsKind(SyntaxKind.CommaToken);
|| prevToken.IsKind(SyntaxKind.CommaToken)
|| prevToken.IsKind(SyntaxKind.ColonToken);
break;

case SyntaxKindEx.ParenthesizedPattern:
Expand Down