Skip to content

Commit 8e4e5ab

Browse files
committed
Implement CR feedback
1 parent f7482c1 commit 8e4e5ab

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/ReadabilityRules/SA1130CodeFixProvider.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ private static SyntaxNode ReplaceWithLambda(AnonymousMethodExpressionSyntax anon
8686
.Concat(parameterList.CloseParenToken.LeadingTrivia)
8787
.Concat(parameterList.CloseParenToken.TrailingTrivia.WithoutTrailingWhitespace())
8888
.Concat(new[] { SyntaxFactory.ElasticSpace });
89-
var leadingTrivia = parameterList.OpenParenToken.LeadingTrivia.Concat(parameterList.OpenParenToken.TrailingTrivia);
89+
var leadingTrivia = parameterList.OpenParenToken.LeadingTrivia
90+
.Concat(parameterList.OpenParenToken.TrailingTrivia)
91+
.Concat(parameterSyntax.GetLeadingTrivia());
9092

91-
parameterSyntax = parameterSyntax.WithLeadingTrivia(leadingTrivia).WithTrailingTrivia(trailingTrivia);
93+
parameterSyntax = parameterSyntax
94+
.WithLeadingTrivia(leadingTrivia)
95+
.WithTrailingTrivia(trailingTrivia);
9296

9397
lambdaExpression = SyntaxFactory.SimpleLambdaExpression(anonymousMethod.AsyncKeyword, parameterSyntax, arrowToken, anonymousMethod.Body);
9498
}
@@ -111,8 +115,9 @@ private static ParameterListSyntax RemoveType(ParameterListSyntax parameterList)
111115
private static ParameterSyntax RemoveType(ParameterSyntax parameterSyntax)
112116
{
113117
var syntax = parameterSyntax.WithType(null)
114-
.WithTrailingTrivia(parameterSyntax.Type.GetLeadingTrivia().Concat(parameterSyntax.DescendantTrivia()));
115-
return syntax.WithTrailingTrivia(syntax.GetTrailingTrivia().WithoutTrailingWhitespace());
118+
.WithLeadingTrivia(parameterSyntax.Type.GetLeadingTrivia().Concat(parameterSyntax.Type.GetTrailingTrivia()));
119+
return syntax.WithTrailingTrivia(syntax.GetTrailingTrivia().WithoutTrailingWhitespace())
120+
.WithLeadingTrivia(syntax.GetLeadingTrivia().WithoutWhitespace());
116121
}
117122

118123
private static bool IsValid(ParameterSyntax parameterSyntax)

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,41 +252,44 @@ private void Method(object o)
252252

253253
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
254254
await this.VerifyCSharpDiagnosticAsync(fixedCode, expectedAfterFix, CancellationToken.None).ConfigureAwait(false);
255-
await this.VerifyCSharpFixAsync(testCode, fixedCode, allowNewCompilerDiagnostics: true).ConfigureAwait(false);
255+
await this.VerifyCSharpFixAsync(testCode, fixedCode, allowNewCompilerDiagnostics: true, numberOfFixAllIterations: 2).ConfigureAwait(false);
256256
}
257257

258258
[Fact]
259259
public async Task TestSimpleDelegateUseWithTriviaAsync()
260260
{
261261
var testCode = @"
262-
using System;
262+
using System; using System.Collections.Generic;
263263
public class TypeName
264264
{
265265
public void Test()
266266
{
267267
Action action1 = /*a*/delegate/*b*/{ };
268268
Action action2 = /*a*/delegate/*b*/(/*c*/)/*d*/ { };
269269
Action<int> action3 = /*a*/delegate/*b*/(/*c*/int/*d*/i/*e*/)/*f*/{ };
270+
Action<List<int>> action4 = delegate(List</* c1 */ int> i) { };
270271
}
271272
}";
272273

273274
string fixedCode = @"
274-
using System;
275+
using System; using System.Collections.Generic;
275276
public class TypeName
276277
{
277278
public void Test()
278279
{
279280
Action action1 = /*a*/()/*b*/ => { };
280281
Action action2 = /*a*//*b*/(/*c*/)/*d*/ => { };
281-
Action<int> action3 = /*a*//*b*//*c*/i/*d*//*e*//*f*/ => { };
282+
Action<int> action3 = /*a*//*b*//*c*//*d*/i/*e*//*f*/ => { };
283+
Action<List<int>> action4 = i => { };
282284
}
283285
}";
284286

285287
var expected = new[]
286288
{
287289
this.CSharpDiagnostic().WithLocation(7, 31),
288290
this.CSharpDiagnostic().WithLocation(8, 31),
289-
this.CSharpDiagnostic().WithLocation(9, 36)
291+
this.CSharpDiagnostic().WithLocation(9, 36),
292+
this.CSharpDiagnostic().WithLocation(10, 37)
290293
};
291294
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
292295
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/CodeFixVerifier.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,11 @@ private static async Task<Document> GetFixAllAnalyzerAsync(FixAllScope scope, Im
235235
break;
236236
}
237237

238-
if (numberOfIterations <= 0)
238+
if (--numberOfIterations < 0)
239239
{
240-
// If we reached 0 we either have not fixed everything we want to fix or the code fix is not supposed to fix all violations.
241-
break;
240+
Assert.True(false, "The upper limit for the number of fix all iterations was exceeded");
242241
}
243242

244-
numberOfIterations--;
245-
246243
string equivalenceKey = null;
247244
foreach (var diagnostic in analyzerDiagnostics)
248245
{

0 commit comments

Comments
 (0)