Repository: domluna/JuliaFormatter.jl
Pull request #750 (2023-08-14 02:28:09)

fix #748


Patch:
diff --git a/Project.toml b/Project.toml
index 31d8933b..96ce8795 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,7 +1,7 @@
 name = "JuliaFormatter"
 uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
 authors = ["Dominique Luna <dluna132@gmail.com>"]
-version = "1.0.35"
+version = "1.0.36"
 
 [deps]
 CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
diff --git a/src/styles/default/nest.jl b/src/styles/default/nest.jl
index 92677fa0..539eeae4 100644
--- a/src/styles/default/nest.jl
+++ b/src/styles/default/nest.jl
@@ -300,7 +300,10 @@ function n_tuple!(ds::DefaultStyle, fst::FST, s::State)
                 n.val = ";"
                 n.len = 1
                 nest!(style, n, s)
-            elseif n.typ === INVERSETRAILINGSEMICOLON
+            elseif n.typ === INVERSETRAILINGSEMICOLON && !(
+                s.opts.join_lines_based_on_source &&
+                (fst.typ === Vcat || fst.typ === TypedVcat)
+            )
                 n.val = ""
                 n.len = 0
                 nest!(style, n, s)
diff --git a/src/styles/sciml/nest.jl b/src/styles/sciml/nest.jl
index a8c51273..9a1ad9fc 100644
--- a/src/styles/sciml/nest.jl
+++ b/src/styles/sciml/nest.jl
@@ -4,13 +4,13 @@ for f in [
     :n_ref!,
     :n_macrocall!,
     :n_typedcomprehension!,
-    :n_typedvcat!,
     :n_tuple!,
     :n_braces!,
     :n_parameters!,
     :n_invisbrackets!,
     :n_comprehension!,
     :n_vcat!,
+    :n_typedvcat!,
     :n_bracescat!,
     :n_generator!,
     :n_filter!,


Test patch:
diff --git a/test/issues.jl b/test/issues.jl
index 85d0799a..ef81dd74 100644
--- a/test/issues.jl
+++ b/test/issues.jl
@@ -1690,4 +1690,20 @@
         @test fmt(s, 4, 92) == s
         @test format_text(s, SciMLStyle()) == s
     end
+
+    @testset "748" begin
+        # this started out as an error with SciMLStyle but I narrowed it down to an edge case
+        # with the `join_lines_based_on_source` option with vcat types
+        str_ = """
+        [0.128483; 1.256853; 0.0030203; 0.0027977; 0.0101511; 0.0422942; 0.2391346;
+                  0.0008014; 0.0001464; 2.67e-05; 4.8e-6; 9e-7; 0.0619917; 1.2444292; 0.0486676;
+                  199.9383546; 137.4267984; 1.5180203; 1.5180203]
+        """
+        str = """
+        [0.128483; 1.256853; 0.0030203; 0.0027977; 0.0101511; 0.0422942; 0.2391346;
+            0.0008014; 0.0001464; 2.67e-05; 4.8e-6; 9e-7; 0.0619917; 1.2444292; 0.0486676;
+            199.9383546; 137.4267984; 1.5180203; 1.5180203]
+        """
+        @test fmt(str_, 4, 92, join_lines_based_on_source=true) == str
+    end
 end
diff --git a/test/options.jl b/test/options.jl
index 0d420ecb..f1032760 100644
--- a/test/options.jl
+++ b/test/options.jl
@@ -2052,6 +2052,10 @@
             @test yasfmt(str_, 4, 50, join_lines_based_on_source = true) == str
         end
 
+        # NOTE: not sure since test makes sense anymore.
+        # It is generally not a great idea to remove the semicolons here since
+        # it can be potentially change the semantics or lead to code errors.
+        # https://github.com/domluna/JuliaFormatter.jl/issues/745
         @testset "matrices" begin
             str_ = """
             T[ a b Expr();
@@ -2059,7 +2063,7 @@
             str = """
             T[a b Expr()
                 d e Expr()]"""
-            @test fmt(str_, join_lines_based_on_source = true) == str
+            @test_broken fmt(str_, join_lines_based_on_source = true) == str
         end
 
         @testset "function defs" begin