Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;
using Xunit;

Expand All @@ -28,5 +29,26 @@ public async Task TestTupleUsingAliasAsync()
var expected = Diagnostic(DescriptorPreceded).WithLocation(0);
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3931, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3931")]
public async Task TestParenthesizedLambdaInCollectionExpressionAsync()
{
var testCode = @"
class TestClass
{
private System.Action[] actions = [ [|(|]) => {}];
}
";

var fixedCode = @"
class TestClass
{
private System.Action[] actions = [() => {}];
}
";

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt

case SyntaxKind.ParameterList:
var partOfLambdaExpression = token.Parent.Parent.IsKind(SyntaxKind.ParenthesizedLambdaExpression);
haveLeadingSpace = partOfLambdaExpression;
var startOfCollectionExpression = prevToken.IsKind(SyntaxKind.OpenBracketToken) && prevToken.Parent.IsKind(SyntaxKindEx.CollectionExpression);
haveLeadingSpace = partOfLambdaExpression && !startOfCollectionExpression;
break;

case SyntaxKindEx.TupleType:
Expand Down