Skip to content

Commit

Permalink
Avoid reporting necessary parenthesis in 'is pattern expression'
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jun 16, 2017
1 parent 05fd524 commit 26c1474
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SA1119CSharp7UnitTests : SA1119UnitTests
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
/// <seealso cref="SA1408CSharp7UnitTests.TestPatternMatchingAsync"/>
[Fact]
[Fact(Skip = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2398")]
public async Task TestPatternMatchingAsync()
{
var testCode = @"public class Foo
Expand All @@ -33,7 +33,7 @@ public void Bar()
{
public void Bar()
{
if ( new object() is bool b && b)
if (new object() is bool b && b)
{
return;
}
Expand All @@ -52,6 +52,25 @@ public void Bar()
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
}

[Fact]
[WorkItem(2372, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2372")]
public async Task TestNegatedPatternMatchingAsync()
{
var testCode = @"public class Foo
{
public void Bar()
{
object obj = null;
if (!(obj is string anythng))
{
// ...
}
}
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestTupleDeconstructionAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace StyleCop.Analyzers.MaintainabilityRules
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.Lightup;

/// <summary>
/// A C# statement contains parenthesis which are unnecessary and should be removed.
Expand Down Expand Up @@ -106,6 +107,7 @@ private static void HandleParenthesizedExpression(SyntaxNodeAnalysisContext cont
&& !node.Expression.IsKind(SyntaxKind.CastExpression)
&& !node.Expression.IsKind(SyntaxKind.ConditionalExpression)
&& !node.Expression.IsKind(SyntaxKind.IsExpression)
&& !node.Expression.IsKind(SyntaxKindEx.IsPatternExpression)
&& !node.Expression.IsKind(SyntaxKind.SimpleLambdaExpression)
&& !node.Expression.IsKind(SyntaxKind.ParenthesizedLambdaExpression)
&& !node.Expression.IsKind(SyntaxKind.ArrayCreationExpression)
Expand Down

0 comments on commit 26c1474

Please sign in to comment.