From 1e1d804fcb6b09e6ce363c98d7a45226f42fce99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hellander?= Date: Sat, 9 Dec 2023 07:45:38 +0100 Subject: [PATCH] Update SA1118 to allow multi-line collection expressions #3732 --- .../SA1118CSharp12UnitTests.cs | 32 +++++++++++++++++++ .../Lightup/SyntaxKindEx.cs | 1 + ...SA1118ParameterMustNotSpanMultipleLines.cs | 1 + 3 files changed, 34 insertions(+) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1118CSharp12UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1118CSharp12UnitTests.cs index 1c122fc5e..f9e1f8c7b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1118CSharp12UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1118CSharp12UnitTests.cs @@ -3,9 +3,41 @@ namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules; + using Xunit; + + using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier< + StyleCop.Analyzers.ReadabilityRules.SA1118ParameterMustNotSpanMultipleLines>; public partial class SA1118CSharp12UnitTests : SA1118CSharp11UnitTests { + [Fact] + [WorkItem(3732, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3732")] + public async Task TestCollectionExpressionAsync() + { + var testCode = @" +class Foo +{ + public void TestMethod() + { + AnotherMethod( + 42, + [ + 1, + 2, + 3 + ]); + } + + public void AnotherMethod(int x, int[] y) + { + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs index ecb9f398b..b3c2d27c6 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs @@ -69,5 +69,6 @@ internal static class SyntaxKindEx public const SyntaxKind RecordDeclaration = (SyntaxKind)9063; public const SyntaxKind FunctionPointerUnmanagedCallingConventionList = (SyntaxKind)9066; public const SyntaxKind RecordStructDeclaration = (SyntaxKind)9068; + public const SyntaxKind CollectionExpression = (SyntaxKind)9076; } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1118ParameterMustNotSpanMultipleLines.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1118ParameterMustNotSpanMultipleLines.cs index 00852f8ea..a2e9dee0f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1118ParameterMustNotSpanMultipleLines.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1118ParameterMustNotSpanMultipleLines.cs @@ -87,6 +87,7 @@ internal class SA1118ParameterMustNotSpanMultipleLines : DiagnosticAnalyzer SyntaxKind.ImplicitArrayCreationExpression, SyntaxKindEx.WithExpression, SyntaxKindEx.ImplicitObjectCreationExpression, + SyntaxKindEx.CollectionExpression, }; ///