Skip to content

Commit bd7c5aa

Browse files
authored
Merge pull request #3483 from sharwell/property-pattern
Support extended property patterns in SA1101
2 parents 0677259 + 8d274a9 commit bd7c5aa

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules
75
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.CSharp;
89
using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules;
10+
using StyleCop.Analyzers.Test.Verifiers;
11+
using Xunit;
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
13+
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
14+
StyleCop.Analyzers.ReadabilityRules.SA1101CodeFixProvider>;
915

1016
public class SA1101CSharp10UnitTests : SA1101CSharp9UnitTests
1117
{
18+
[Fact]
19+
[WorkItem(3472, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3472")]
20+
public async Task TestExtendedPropertyPatternAsync()
21+
{
22+
var testCode = @"public class Test
23+
{
24+
public Test Inner;
25+
public string Value;
26+
27+
public bool Method(Test arg)
28+
{
29+
return arg is { Inner.Value: """" };
30+
}
31+
}";
32+
33+
await new CSharpTest(LanguageVersion.CSharp10)
34+
{
35+
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
36+
TestCode = testCode,
37+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
38+
}
1239
}
1340
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/ReadabilityRules/SA1101CSharp7UnitTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp7.ReadabilityRules
75
{
86
using System.Threading;
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp8.ReadabilityRules
75
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp7.ReadabilityRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
13+
StyleCop.Analyzers.ReadabilityRules.SA1101CodeFixProvider>;
914

1015
public class SA1101CSharp8UnitTests : SA1101CSharp7UnitTests
1116
{
17+
[Fact]
18+
[WorkItem(3472, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3472")]
19+
public async Task TestPropertyPatternAsync()
20+
{
21+
var testCode = @"public class Test
22+
{
23+
public Test Inner;
24+
public string Value;
25+
26+
public bool Method(Test arg)
27+
{
28+
return arg is { Value: """" };
29+
}
30+
}";
31+
32+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
33+
}
1234
}
1335
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1101CSharp9UnitTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
75
{
86
using System.Threading;

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1101UnitTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.ReadabilityRules
75
{
86
using System.Threading;

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1101PrefixLocalCallsWithThis.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ private static bool HasThis(SyntaxNode node)
281281
case SyntaxKind.Attribute:
282282
return false;
283283

284+
case SyntaxKindEx.RecursivePattern:
285+
return false;
286+
284287
default:
285288
continue;
286289
}

0 commit comments

Comments
 (0)