Skip to content

Commit

Permalink
Merge pull request #3483 from sharwell/property-pattern
Browse files Browse the repository at this point in the history
Support extended property patterns in SA1101
  • Loading branch information
sharwell authored Apr 18, 2022
2 parents 0677259 + 8d274a9 commit bd7c5aa
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules;
using StyleCop.Analyzers.Test.Verifiers;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
StyleCop.Analyzers.ReadabilityRules.SA1101CodeFixProvider>;

public class SA1101CSharp10UnitTests : SA1101CSharp9UnitTests
{
[Fact]
[WorkItem(3472, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3472")]
public async Task TestExtendedPropertyPatternAsync()
{
var testCode = @"public class Test
{
public Test Inner;
public string Value;
public bool Method(Test arg)
{
return arg is { Inner.Value: """" };
}
}";

await new CSharpTest(LanguageVersion.CSharp10)
{
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
TestCode = testCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp7.ReadabilityRules
{
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp8.ReadabilityRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp7.ReadabilityRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
StyleCop.Analyzers.ReadabilityRules.SA1101CodeFixProvider>;

public class SA1101CSharp8UnitTests : SA1101CSharp7UnitTests
{
[Fact]
[WorkItem(3472, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3472")]
public async Task TestPropertyPatternAsync()
{
var testCode = @"public class Test
{
public Test Inner;
public string Value;
public bool Method(Test arg)
{
return arg is { Value: """" };
}
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
{
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.ReadabilityRules
{
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ private static bool HasThis(SyntaxNode node)
case SyntaxKind.Attribute:
return false;

case SyntaxKindEx.RecursivePattern:
return false;

default:
continue;
}
Expand Down

0 comments on commit bd7c5aa

Please sign in to comment.