Skip to content

Commit

Permalink
Update SA1008 to handle positional patterns inside property patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhellander committed Nov 18, 2022
1 parent 224763f commit 79c6959
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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

0 comments on commit 79c6959

Please sign in to comment.