Skip to content

Commit f2e2cbd

Browse files
committed
Update SA1008 to support tuple types and expressions
Fixes #2308
1 parent 3761711 commit f2e2cbd

5 files changed

Lines changed: 752 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1000CSharp7UnitTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using StyleCop.Analyzers.Test.SpacingRules;
89
using TestHelper;
@@ -71,5 +72,59 @@ ref @Int32 Call(ref @Int32 p)
7172

7273
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false);
7374
}
75+
76+
/// <summary>
77+
/// Verifies that spacing for tuple expressions is handled properly.
78+
/// </summary>
79+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
80+
/// <seealso cref="SA1008CSharp7UnitTests.TestTupleExpressionsAsync"/>
81+
[Fact]
82+
public async Task TestReturnTupleExpressionsAsync()
83+
{
84+
var testCode = @"using System.Collections.Generic;
85+
86+
namespace TestNamespace
87+
{
88+
public class TestClass
89+
{
90+
public void TestMethod()
91+
{
92+
// Returns (leading spaces after keyword checked in SA1000, not SA1008)
93+
(int, int) LocalFunction1() { return( 1, 2); }
94+
(int, int) LocalFunction2() { return(1, 2); }
95+
(int, int) LocalFunction3() { return ( 1, 2); }
96+
}
97+
}
98+
}
99+
";
100+
101+
var fixedCode = @"using System.Collections.Generic;
102+
103+
namespace TestNamespace
104+
{
105+
public class TestClass
106+
{
107+
public void TestMethod()
108+
{
109+
// Returns (leading spaces after keyword checked in SA1000, not SA1008)
110+
(int, int) LocalFunction1() { return ( 1, 2); }
111+
(int, int) LocalFunction2() { return (1, 2); }
112+
(int, int) LocalFunction3() { return ( 1, 2); }
113+
}
114+
}
115+
}
116+
";
117+
118+
DiagnosticResult[] expectedDiagnostics =
119+
{
120+
// Returns
121+
this.CSharpDiagnostic().WithArguments("return", string.Empty, "followed").WithLocation(10, 43),
122+
this.CSharpDiagnostic().WithArguments("return", string.Empty, "followed").WithLocation(11, 43),
123+
};
124+
125+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
126+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
127+
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
128+
}
74129
}
75130
}

0 commit comments

Comments
 (0)