Skip to content

Commit 2df902e

Browse files
committed
Report SA1108 on line end (fix #2941)
1 parent 3d0c548 commit 2df902e

2 files changed

Lines changed: 99 additions & 7 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/SA1008UnitTests.cs

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,44 @@ public void TestMethod1(
137137
int z)
138138
{
139139
}
140+
141+
public void TestMethod2 (
142+
int x,
143+
int y,
144+
int z)
145+
{
146+
}
140147
}
141148
}
142149
";
143150

144-
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
151+
var fixedTestCode = @"namespace TestNamespace
152+
{
153+
public class TestClass
154+
{
155+
public void TestMethod1(
156+
int x,
157+
int y,
158+
int z)
159+
{
160+
}
161+
162+
public void TestMethod2(
163+
int x,
164+
int y,
165+
int z)
166+
{
167+
}
168+
}
169+
}
170+
";
171+
172+
DiagnosticResult[] expectedDiagnostics =
173+
{
174+
Diagnostic(DescriptorNotPreceded).WithLocation(12, 33),
175+
};
176+
177+
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
145178
}
146179

147180
/// <summary>
@@ -781,6 +814,71 @@ public TestClass()
781814
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
782815
}
783816

817+
/// <summary>
818+
/// Verifies that spacing for multiline argument lists is handled properly.
819+
/// </summary>
820+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
821+
[Fact]
822+
public async Task TestMultiLineArgumentListAsync()
823+
{
824+
var testCode = @"using System;
825+
826+
namespace TestNamespace
827+
{
828+
public class TestClass
829+
{
830+
public TestClass(int x, int y)
831+
{
832+
var s1 = new String(
833+
'a',
834+
x);
835+
836+
var s2 = new String (
837+
'a',
838+
y);
839+
840+
// Opening parenthesis followed by space
841+
var s3 = new String(
842+
'a',
843+
x);
844+
}
845+
}
846+
}
847+
";
848+
849+
var fixedTestCode = @"using System;
850+
851+
namespace TestNamespace
852+
{
853+
public class TestClass
854+
{
855+
public TestClass(int x, int y)
856+
{
857+
var s1 = new String(
858+
'a',
859+
x);
860+
861+
var s2 = new String(
862+
'a',
863+
y);
864+
865+
// Opening parenthesis followed by space
866+
var s3 = new String('a',
867+
x);
868+
}
869+
}
870+
}
871+
";
872+
873+
DiagnosticResult[] expectedDiagnostics =
874+
{
875+
Diagnostic(DescriptorNotPreceded).WithLocation(13, 33),
876+
Diagnostic(DescriptorNotFollowed).WithLocation(18, 32),
877+
};
878+
879+
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
880+
}
881+
784882
/// <summary>
785883
/// Verifies that spacing for while statements is handled properly.
786884
/// </summary>

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
9292
return;
9393
}
9494

95-
if (token.IsLastInLine())
96-
{
97-
// ignore open parenthesis when last on line.
98-
return;
99-
}
100-
10195
var prevToken = token.GetPreviousToken();
10296

10397
// Don't check leading spaces when preceded by a keyword that is already handled by SA1000

0 commit comments

Comments
 (0)