Repository: domluna/JuliaFormatter.jl (julia)

Issue:
Avoid removal of semicolon in vertical concatenation
The following code

```julia
[
  a;
]
```

is currently formatted to

```julia
[
  a
]
```

which, for `a::AbstractVector` is no longer equivalent because the former is a "flattened" vector whereas the latter is a vector of vector.

Pull request description:
Depending on the types inside a vector

```
[
  ...
]
```

Having removing or adding the semicolon can change the type entirely.

```
julia> [
       [1,0];
       ]
2-element Vector{Int64}:
 1
 0

julia> [
       [1,0]
       ]
1-element Vector{Vector{Int64}}:
 [1, 0]
```

So we should no longer do that.

fix https://github.com/domluna/JuliaFormatter.jl/issues/655

Patch:
diff --git a/src/styles/default/pretty.jl b/src/styles/default/pretty.jl
index f29c85073..3b546b8ac 100644
--- a/src/styles/default/pretty.jl
+++ b/src/styles/default/pretty.jl
@@ -2150,7 +2150,7 @@ function p_vcat(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
                 add_node!(t, Placeholder(1), s)
                 # Keep trailing semicolon if there's only one arg
             elseif length(args) == 1 && has_semicolon(s.doc, n.startline)
-                add_node!(t, InverseTrailingSemicolon(), s)
+                add_node!(t, Semicolon(), s)
                 add_node!(t, Placeholder(0), s)
             else
                 add_node!(t, Placeholder(0), s)


Test patch:
diff --git a/test/issues.jl b/test/issues.jl
index a5bb38298..fcbeec048 100644
--- a/test/issues.jl
+++ b/test/issues.jl
@@ -1486,4 +1486,22 @@
         """
         @test fmt(s, 4, 92, align_assignment = true) == s
     end
+
+    @testset "655" begin
+        s = """
+        [
+          a;
+        ]
+        """
+        @test fmt(s, 2, 92, join_lines_based_on_source = true) == s
+        @test fmt(s, 2, 1) == s
+        s = """
+        [
+          a
+        ]
+        """
+        @test fmt(s, 2, 92, join_lines_based_on_source = true, trailing_comma = nothing) ==
+              s
+        @test fmt(s, 2, 1, trailing_comma = nothing) == s
+    end
 end