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.Test/AttributeTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/AttributeTests.cs
index a39c156d6..fb387eac6 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/AttributeTests.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/AttributeTests.cs
@@ -22,5 +22,15 @@ public void TestNoDiagnosticAttributeReason()
var attribute = new NoDiagnosticAttribute(reason);
Assert.Same(reason, attribute.Reason);
}
+
+ [Fact]
+ public void TestWorkItemAttribute()
+ {
+ int id = 1234;
+ string issueUri = "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2419";
+ var attribute = new WorkItemAttribute(id, issueUri);
+ Assert.Equal(id, attribute.Id);
+ Assert.Same(issueUri, attribute.Location);
+ }
}
}
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj b/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj
index 00d9dc180..6a653acf0 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj
@@ -423,6 +423,7 @@
+
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/WorkItemAttribute.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/WorkItemAttribute.cs
new file mode 100644
index 000000000..afd1e5dfe
--- /dev/null
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/WorkItemAttribute.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
+// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
+
+namespace StyleCop.Analyzers.Test
+{
+ using System;
+
+ ///
+ /// Used to tag test methods or types which are created for a given WorkItem
+ ///
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
+ public sealed class WorkItemAttribute : Attribute
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The ID of the issue in the original tracker where the work item was first reported. This
+ /// could be a GitHub issue or pull request number, or the number of a Microsoft-internal bug.
+ /// The URI where the work item can be viewed. This is a link to work item
+ /// in the original source.
+ public WorkItemAttribute(int id, string issueUri)
+ {
+ this.Id = id;
+ this.Location = issueUri;
+ }
+
+ public int Id
+ {
+ get;
+ }
+
+ public string Location
+ {
+ get;
+ }
+ }
+}
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)