diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/MaintainabilityRules/SA1119CSharp7UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/MaintainabilityRules/SA1119CSharp7UnitTests.cs index 781522c2e..2b060d401 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/MaintainabilityRules/SA1119CSharp7UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/MaintainabilityRules/SA1119CSharp7UnitTests.cs @@ -16,7 +16,7 @@ public class SA1119CSharp7UnitTests : SA1119UnitTests /// /// A representing the asynchronous unit test. /// - [Fact] + [Fact(Skip = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2398")] public async Task TestPatternMatchingAsync() { var testCode = @"public class Foo @@ -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; } @@ -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() { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs index 5ae5c96a9..07cf9ab2f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs @@ -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; /// /// A C# statement contains parenthesis which are unnecessary and should be removed. @@ -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)