diff --git a/.github/workflows/format_repositories.yml b/.github/workflows/format_repositories.yml index 69e7009cc..b26e11fcb 100644 --- a/.github/workflows/format_repositories.yml +++ b/.github/workflows/format_repositories.yml @@ -14,7 +14,7 @@ jobs: path: csharpier - uses: actions/setup-dotnet@v1 with: - dotnet-version: '7.0.304' + dotnet-version: '7.0.400' - uses: actions/checkout@v2 with: repository: belav/csharpier-repos diff --git a/.github/workflows/publish_nuget.yml b/.github/workflows/publish_nuget.yml index ba9d593d4..216e4317a 100644 --- a/.github/workflows/publish_nuget.yml +++ b/.github/workflows/publish_nuget.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/setup-dotnet@v1 with: dotnet-version: | - 7.0.304 + 7.0.400 6.0.300 - run: > dotnet test Src/CSharpier.Tests/CSharpier.Tests.csproj @@ -32,7 +32,7 @@ jobs: - uses: actions/setup-dotnet@v1 with: dotnet-version: | - 7.0.304 + 7.0.400 6.0.300 - name: Publish CSharpier.Core library on version change uses: alirezanet/publish-nuget@v3.0.4 diff --git a/.github/workflows/validate_pull_request.yml b/.github/workflows/validate_pull_request.yml index f3248bdda..e3d148517 100644 --- a/.github/workflows/validate_pull_request.yml +++ b/.github/workflows/validate_pull_request.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/setup-dotnet@v1 with: dotnet-version: | - 7.0.304 + 7.0.400 6.0.300 - run: > dotnet test CSharpier.sln @@ -28,7 +28,7 @@ jobs: - uses: actions/setup-dotnet@v1 with: dotnet-version: | - 7.0.304 + 7.0.400 6.0.300 - run: | dotnet tool restore @@ -41,7 +41,7 @@ jobs: - uses: actions/setup-dotnet@v1 with: dotnet-version: | - 7.0.304 + 7.0.400 6.0.300 - run: | dotnet build Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj diff --git a/Directory.Packages.props b/Directory.Packages.props index 37383771f..3241fa18d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,10 +13,10 @@ - - + + - + @@ -29,8 +29,8 @@ - + - + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 52c861fc3..d58a812e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base WORKDIR /app EXPOSE 80 -FROM mcr.microsoft.com/dotnet/sdk:7.0.304 AS build +FROM mcr.microsoft.com/dotnet/sdk:7.0.400 AS build RUN apt-get update && \ apt-get install curl gnupg -yq && \ diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test new file mode 100644 index 000000000..041770be4 --- /dev/null +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/CollectionExpressions.test @@ -0,0 +1,18 @@ +int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; + +Span b = [ 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i' ]; + +string[] c = +[ + "________________________", + "________________________", + "________________________", + "________________________" +]; + +int[][] d = +[ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9] +]; diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/CollectionExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/CollectionExpression.cs new file mode 100644 index 000000000..57322b9fb --- /dev/null +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/CollectionExpression.cs @@ -0,0 +1,38 @@ +namespace CSharpier.SyntaxPrinter.SyntaxNodePrinters; + +internal static class CollectionExpression +{ + public static Doc Print(CollectionExpressionSyntax node, FormattingContext context) + { + Doc separator = node.Parent + is AssignmentExpressionSyntax + or EqualsValueClauseSyntax { Parent: not PropertyDeclarationSyntax } + ? Doc.Line + : Doc.Null; + + var alwaysBreak = + node.Elements.FirstOrDefault() + is ExpressionElementSyntax { Expression: CollectionExpressionSyntax }; + + var result = Doc.Concat( + separator, + Token.Print(node.OpenBracketToken, context), + Doc.Indent( + alwaysBreak ? Doc.HardLine : Doc.Line, + SeparatedSyntaxList.Print( + node.Elements, + Node.Print, + alwaysBreak ? Doc.HardLine : Doc.Line, + context + ) + ), + node.Elements.Any() + ? alwaysBreak + ? Doc.HardLine + : Doc.Line + : Doc.Null, + Token.Print(node.CloseBracketToken, context) + ); + return Doc.Group(result); + } +} diff --git a/global.json b/global.json index 065581b4a..0c4b7f5ec 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.304", + "version": "7.0.400", "rollForward": "latestFeature" } }