Repository: domluna/JuliaFormatter.jl
Pull request #145 (2019-12-02 00:34:59)

Update Dependencies + misc bugs


Patch:
diff --git a/Manifest.toml b/Manifest.toml
index eca92720..771159e6 100644
--- a/Manifest.toml
+++ b/Manifest.toml
@@ -5,9 +5,9 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
 
 [[CSTParser]]
 deps = ["Tokenize"]
-git-tree-sha1 = "99dda94f5af21a4565dc2b97edf6a95485f116c3"
+git-tree-sha1 = "39ba1205b6ddd4c7fa4d0ba6f2f98774a9b92d2c"
 uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
-version = "1.0.0"
+version = "1.1.0"
 
 [[Distributed]]
 deps = ["Random", "Serialization", "Sockets"]
@@ -39,6 +39,6 @@ deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
 uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
 
 [[Tokenize]]
-git-tree-sha1 = "dfcdbbfb2d0370716c815cbd6f8a364efb6f42cf"
+git-tree-sha1 = "c3aab236f122445406cf7a6de8af0b794da5a950"
 uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
-version = "0.5.6"
+version = "0.5.7"
diff --git a/src/JuliaFormatter.jl b/src/JuliaFormatter.jl
index 2d5f1c82..9715480a 100644
--- a/src/JuliaFormatter.jl
+++ b/src/JuliaFormatter.jl
@@ -1,7 +1,7 @@
 module JuliaFormatter
 
 using CSTParser
-using CSTParser.Tokenize
+using Tokenize
 
 export format, format_text, format_file, format_dir
 
diff --git a/src/nest.jl b/src/nest.jl
index 43cd05fa..2a114dce 100644
--- a/src/nest.jl
+++ b/src/nest.jl
@@ -80,6 +80,7 @@ function dedent!(x::PTree, s::State)
 
     # dedent
     x.indent -= s.indent_size
+    x.force_nest && return
 
     nl_inds = findall(n -> n.typ === NEWLINE && !n.force_nest, x.nodes)
     length(nl_inds) > 0 || return
@@ -192,10 +193,13 @@ function n_import!(x, s)
     idx = findfirst(n -> n.typ === PLACEHOLDER, x.nodes)
     if idx !== nothing && (line_margin > s.margin || x.force_nest)
         x.indent += s.indent_size
-        if x.indent + sum(length.(x[idx+1:end])) <= s.margin
-            x[idx] = Newline(length = x[idx].len)
-            walk(reset_line_offset!, x, s)
-            return
+
+        if !x.force_nest
+            if x.indent + sum(length.(x[idx+1:end])) <= s.margin
+                x[idx] = Newline(length = x[idx].len)
+                walk(reset_line_offset!, x, s)
+                return
+            end
         end
 
         for (i, n) in enumerate(x.nodes)
diff --git a/src/pretty.jl b/src/pretty.jl
index 9546066b..4f204a5c 100644
--- a/src/pretty.jl
+++ b/src/pretty.jl
@@ -131,27 +131,6 @@ function get_args(args::Vector{CSTParser.EXPR})
     args0
 end
 
-function get_args(x::PTree)
-    is_iterable(x) || error("get_args requires an iterable PTree type")
-    sidx = findfirst(is_opener, x.nodes)
-    sidx === nothing && (sidx = 1)
-    args = PTree[]
-    for i = sidx:length(x.nodes)
-        arg = x.nodes[i]
-        arg.typ === CSTParser.PUNCTUATION && continue
-        arg.typ isa PLeaf && continue
-        if arg.typ === CSTParser.Parameters
-            for j = 1:length(arg.nodes)
-                parg = arg.nodes[j]
-                push!(args, parg)
-            end
-        else
-            push!(args, arg)
-        end
-    end
-    args
-end
-
 n_args(x) = length(get_args(x))
 
 function add_node!(t::PTree, n::PTree, s::State; join_lines = false, max_padding = -1)
@@ -235,7 +214,7 @@ function add_node!(t::PTree, n::PTree, s::State; join_lines = false, max_padding
         notcode_endline = n.startline - 1
         nt = t.nodes[end].typ
 
-        if notcode_startline <= notcode_endline && n.typ !== CSTParser.LITERAL
+        if notcode_startline <= notcode_endline
             # If there are comments in between node elements
             # nesting is forced in an effort to preserve them.
             t.force_nest = true


Test patch:
diff --git a/test/runtests.jl b/test/runtests.jl
index 59fe01ca..6922a195 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -2034,6 +2034,15 @@ end
         """
         @test fmt(str) == str
 
+        str = """
+        foo = [
+            # comment
+            1,
+            2,
+            3,
+        ]"""
+        @test fmt(str) == str
+
     end
 
     @testset "pretty" begin