From 1c49cb2fc3aad502f11120054838fd68e575add0 Mon Sep 17 00:00:00 2001 From: Nozziel Date: Sun, 19 Mar 2017 10:06:08 +0100 Subject: [PATCH] #2308 - SA1008 triggered by typle return types on a method (c# version 7) - Fixed --- .../SpacingRules/SA1008UnitTests.cs | 84 +++++++++++++++++++ ...OpeningParenthesisMustBeSpacedCorrectly.cs | 6 +- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1008UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1008UnitTests.cs index f5b42dd0d..ec4f0a612 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1008UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1008UnitTests.cs @@ -2032,6 +2032,90 @@ class ClassName await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } + /// + /// Verifies that spacing for public tuple return type is handled properly. + /// + /// A representing the asynchronous unit test. + [Fact(Skip = "Tuples currently require System.ValueTuple nuget package to be installed")] + public async Task TestNoFalsePositiveOnPublicTupleReturnAsync() + { + var testCode = @"namespace TestNamespace +{ + public class TestClass + { + public (string primary, string alternate) CalculateMetaphone(string word) + { + } + } +} +"; + + await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } + + /// + /// Verifies that spacing for internal tuple return type is handled properly. + /// + /// A representing the asynchronous unit test. + [Fact(Skip = "Tuples currently require System.ValueTuple nuget package to be installed")] + public async Task TestNoFalsePositiveOnInternalTupleReturnAsync() + { + var testCode = @"namespace TestNamespace +{ + internal class TestClass + { + public (string primary, string alternate) CalculateMetaphone(string word) + { + } + } +} +"; + + await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } + + /// + /// Verifies that spacing for private tuple return type is handled properly. + /// + /// A representing the asynchronous unit test. + [Fact(Skip = "Tuples currently require System.ValueTuple nuget package to be installed")] + public async Task TestNoFalsePositiveOnPrivateTupleReturnAsync() + { + var testCode = @"namespace TestNamespace +{ + private class TestClass + { + public (string primary, string alternate) CalculateMetaphone(string word) + { + } + } +} +"; + + await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } + + /// + /// Verifies that spacing for protected tuple return type is handled properly. + /// + /// A representing the asynchronous unit test. + [Fact(Skip = "Tuples currently require System.ValueTuple nuget package to be installed")] + public async Task TestNoFalsePositiveProtectedOnTupleReturnAsync() + { + var testCode = @"namespace TestNamespace +{ + protected class TestClass + { + public (string primary, string alternate) CalculateMetaphone(string word) + { + } + } +} +"; + + await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } + /// protected override IEnumerable GetCSharpDiagnosticAnalyzers() { diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs index 0f6565e29..ac4d8170c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs @@ -134,7 +134,11 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt case SyntaxKind.WhereKeyword: case SyntaxKind.WhileKeyword: case SyntaxKind.YieldKeyword: - precededByKeyword = true; + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.InternalKeyword: + case SyntaxKind.ProtectedKeyword: + precededByKeyword = true; break; default: