Repository: domluna/JuliaFormatter.jl
Pull request #345 (2021-01-01 07:40:04)

Nest on single arguments in iterable types unless it's a single argument of the syntactic form {...}, [...], (...)
ref #338

The gist is

1. Single arguments are now nested. Before we used a heuristic where if (using a Call as an example) there was a single argument `foo("hello")`. Then `"hello"` would not be nested, now if it exceeds the length it will become:

```
foo(
    "hello",
)
```

The main benefit of this being the formatter is more consistent when it comes to nesting, the second being the previous behavior caused subpar formats in certain cases, as shown in the above issue.

A downside of this (and why it was the way was) is we can get deeply nested structure in cases where joining multiple lines
would be desirable.

```
var = foo1(
  foo2(
    foo3(
      foo4(
        "hellooooooooooooooooooooooooooooooooooooooooooooooooooooo",
      ),
    ),
  ),
)
```

In this example we could join all the `foo*` calls on a single line

2. More sophisticated unnesting

This allows the `foo*` calls in the above example to be joined onto a single line so the upside of the previous behavior is maintained. 

A current caveat is this only works inside a nested binary op call and is the reason why this is a draft. I'm going to extend this to a top-level unnest function next.

That being said it may be worth merging this as is

> As an aside other formatter's don't make this attempt to unnest in these cases and it may only make contrived test cases format better so pursuing this may not be worthwhile. Instead we could just go with 1) and call it :thinking: 

## UPDATE

2) is being scrapped. Instead we'll keep the current behavior there is a single argument and it's of the syntactic form (...), [...], or {...}

Applying this to the above foo* example it will format as

```
var = foo1(
  foo2(
    foo3(
      foo4(
        "hellooooooooooooooooooooooooooooooooooooooooooooooooooooo",
      ),
    ),
  ),
)
```

but if the nested foo* were not present it would format as

```
var = foo1((((
  "hellooooooooooooooooooooooooooooooooooooooooooooooooooooo",
))))
```

To me this is a reasonable middle ground because the parenthesis without a prefix don't add any context when nested, it's syntactically superfluous.




Patch:
diff --git a/Project.toml b/Project.toml
index 8d307daf..d1af9a85 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 = "0.11.0"
+version = "0.12.0"
 
 [deps]
 CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
diff --git a/src/JuliaFormatter.jl b/src/JuliaFormatter.jl
index 136fd0e6..a66c25c7 100644
--- a/src/JuliaFormatter.jl
+++ b/src/JuliaFormatter.jl
@@ -362,8 +362,9 @@ function format_text(cst::CSTParser.EXPR, style::AbstractStyle, s::State)
 
     _, ps = CSTParser.parse(CSTParser.ParseState(text), true)
     line, offset = ps.lt.endpos
-    ps.errored &&
-        error("Parsing error for formatted text:\n\n$text\n\n Error occured on line $line, offset $offset.")
+    ps.errored && error(
+        "Parsing error for formatted text:\n\n$text\n\n Error occured on line $line, offset $offset.",
+    )
     return text
 end
 
diff --git a/src/fst.jl b/src/fst.jl
index 570a2c34..911e0d1c 100644
--- a/src/fst.jl
+++ b/src/fst.jl
@@ -220,7 +220,8 @@ function get_args(cst::CSTParser.EXPR)
        cst.typ === CSTParser.TypedVcat ||
        cst.typ === CSTParser.Ref ||
        cst.typ === CSTParser.Curly ||
-       cst.typ === CSTParser.Call
+       cst.typ === CSTParser.Call ||
+       cst.typ === CSTParser.TypedComprehension
         return get_args(cst.args[2:end])
     elseif cst.typ === CSTParser.WhereOpCall
         # get the arguments in B of `A where B`
@@ -231,7 +232,8 @@ function get_args(cst::CSTParser.EXPR)
            cst.typ === CSTParser.TupleH ||
            cst.typ === CSTParser.Vect ||
            cst.typ === CSTParser.InvisBrackets ||
-           cst.typ === CSTParser.Parameters
+           cst.typ === CSTParser.Parameters ||
+           cst.typ === CSTParser.Comprehension
         return get_args(cst.args)
     end
     CSTParser.get_args(cst)
@@ -514,6 +516,12 @@ function is_iterable(x::Union{CSTParser.EXPR,FST})
     return false
 end
 
+function is_comprehension(x::Union{CSTParser.EXPR,FST})
+    x.typ === CSTParser.Comprehension && return true
+    x.typ === CSTParser.TypedComprehension && return true
+    return false
+end
+
 function is_block(x::Union{CSTParser.EXPR,FST})
     x.typ === CSTParser.If && return true
     x.typ === CSTParser.Do && return true
@@ -596,12 +604,16 @@ end
 
 nest_assignment(cst::CSTParser.EXPR) = is_assignment(cst[2].kind)
 
-function unnestable_arg(cst::CSTParser.EXPR)
-    is_iterable(cst) && return true
-    is_str(cst) && return true
-    cst.typ === CSTParser.LITERAL && return true
-    cst.typ === CSTParser.UnaryOpCall && cst[2].kind === Tokens.DDDOT && return true
-    cst.typ === CSTParser.BinaryOpCall && cst[2].kind === Tokens.DOT && return true
+"""
+`cst` is assumed to be a single child node. Returns true if the node is of the syntactic form `{...}, [...], or (...)`.
+"""
+function unnestable_node(cst::CSTParser.EXPR)
+    cst.typ === CSTParser.TupleH && return true
+    cst.typ === CSTParser.Vect && return true
+    cst.typ === CSTParser.Braces && return true
+    cst.typ === CSTParser.BracesCat && return true
+    cst.typ === CSTParser.Comprehension && return true
+    cst.typ === CSTParser.InvisBrackets && return true
     return false
 end
 
diff --git a/src/markdown.jl b/src/markdown.jl
index 380b51e8..fbbb5405 100644
--- a/src/markdown.jl
+++ b/src/markdown.jl
@@ -16,16 +16,18 @@ function format_md(text::AbstractString, style::AbstractStyle; kwargs...)
 end
 
 function format_md(text::AbstractString, style::AbstractStyle, opts::Options)
-    markdown(enable!(
-        Parser(),
-        [
-            AdmonitionRule(),
-            FootnoteRule(),
-            MathRule(),
-            TableRule(),
-            FormatRule(style, opts),
-        ],
-    )(
-        text,
-    ))
+    markdown(
+        enable!(
+            Parser(),
+            [
+                AdmonitionRule(),
+                FootnoteRule(),
+                MathRule(),
+                TableRule(),
+                FormatRule(style, opts),
+            ],
+        )(
+            text,
+        ),
+    )
 end
diff --git a/src/nest_utils.jl b/src/nest_utils.jl
index 7f212f4f..6579031c 100644
--- a/src/nest_utils.jl
+++ b/src/nest_utils.jl
@@ -53,7 +53,7 @@ function add_indent!(fst::FST, s::State, indent)
 end
 
 # unnest, converts newlines to whitespace
-function unnest!(fst::FST, nl_inds::Vector{Int})
+function nl_to_ws!(fst::FST, nl_inds::Vector{Int})
     for (i, ind) in enumerate(nl_inds)
         fst[ind] = Whitespace(fst[ind].len)
         i == length(nl_inds) || continue
@@ -71,28 +71,38 @@ function unnest!(fst::FST, nl_inds::Vector{Int})
     end
 end
 
+function nl_to_ws!(fst::FST, s::State)
+    nl_inds = findall(n -> n.typ === NEWLINE && can_nest(n), fst.nodes)
+    length(nl_inds) > 0 || return
+    margin = s.line_offset + fst.extra_margin + length(fst)
+    margin <= s.opts.margin && nl_to_ws!(fst, nl_inds)
+    return
+end
+
 function dedent!(fst::FST, s::State)
+    if is_closer(fst) || fst.typ === NOTCODE
+        fst.indent -= s.opts.indent
+    elseif is_leaf(fst) || fst.typ === CSTParser.StringH
+        return
+    else
+        fst.indent -= s.opts.indent
+    end
+end
+
+function unnest!(fst::FST, s::State)
     if is_leaf(fst)
         s.line_offset += length(fst)
-        if is_closer(fst) || fst.typ === NOTCODE
-            fst.indent -= s.opts.indent
-        end
-        return
-    elseif fst.typ === CSTParser.StringH
-        return
     end
 
-    # dedent
-    fst.indent -= s.opts.indent
+    dedent!(fst, s)
 
-    # only unnest if it's allowed
-    can_nest(fst) || return
+    if is_leaf(fst) || fst.typ === CSTParser.StringH || !can_nest(fst)
+        return
+    end
 
-    nl_inds = findall(n -> n.typ === NEWLINE && can_nest(n), fst.nodes)
-    length(nl_inds) > 0 || return
-    margin = s.line_offset + fst.extra_margin + length(fst)
-    margin <= s.opts.margin || return
-    unnest!(fst, nl_inds)
+    nl_to_ws!(fst, s)
+
+    return
 end
 
 """
diff --git a/src/styles/default/nest.jl b/src/styles/default/nest.jl
index 47e84b7d..c75a85c1 100644
--- a/src/styles/default/nest.jl
+++ b/src/styles/default/nest.jl
@@ -594,7 +594,7 @@ function n_binaryopcall!(ds::DefaultStyle, fst::FST, s::State)
                 fst[i1] = Whitespace(1)
                 if indent_nest
                     fst[i2] = Whitespace(0)
-                    walk(dedent!, rhs, s)
+                    walk(unnest!, rhs, s)
                 end
             end
         end
diff --git a/src/styles/default/pretty.jl b/src/styles/default/pretty.jl
index dba72dce..409baa52 100644
--- a/src/styles/default/pretty.jl
+++ b/src/styles/default/pretty.jl
@@ -332,18 +332,20 @@ function format_docstring(style::AbstractStyle, state::State, text::AbstractStri
             String(take!(deindented))
         end
     # then, we format
-    formatted = markdown(enable!(
-        Parser(),
-        [
-            AdmonitionRule(),
-            FootnoteRule(),
-            MathRule(),
-            TableRule(),
-            FormatRule(style, state.opts),
-        ],
-    )(
-        deindented_string,
-    ))
+    formatted = markdown(
+        enable!(
+            Parser(),
+            [
+                AdmonitionRule(),
+                FootnoteRule(),
+                MathRule(),
+                TableRule(),
+                FormatRule(style, state.opts),
+            ],
+        )(
+            deindented_string,
+        ),
+    )
     # Indent all non-first lines to match the current parser indent
     buf = IOBuffer()
     indent = " "^state_indent
@@ -566,7 +568,7 @@ function p_macrocall(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     t = FST(cst, nspaces(s))
 
     args = get_args(cst)
-    nest = length(args) > 0 && !(length(args) == 1 && unnestable_arg(args[1]))
+    nest = length(args) > 0 && !(length(args) == 1 && unnestable_node(args[1]))
     has_closer = is_closer(cst.args[end])
 
     # !has_closer && length(t.nodes) > 1 && (t.typ = MacroBlock)
@@ -1450,7 +1452,7 @@ function p_whereopcall(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     add_node!(t, Whitespace(1), s)
 
     args = get_args(cst.args[3:end])
-    nest = length(args) > 0 && !(length(args) == 1 && unnestable_arg(args[1]))
+    nest = length(args) > 0 && !(length(args) == 1 && unnestable_node(args[1]))
     add_braces =
         !CSTParser.is_lbrace(cst[3]) &&
         cst.parent.typ !== CSTParser.Curly &&
@@ -1539,7 +1541,7 @@ function p_curly(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     add_node!(t, pretty(style, cst[2], s), s, join_lines = true)
 
     args = get_args(cst)
-    nest = length(args) > 0 && !(length(args) == 1 && unnestable_arg(cst[1]))
+    nest = length(args) > 0 && !(length(args) == 1 && unnestable_node(args[1]))
 
     nws = s.opts.whitespace_typedefs ? 1 : 0
     if nest
@@ -1570,7 +1572,7 @@ function p_call(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     add_node!(t, pretty(style, cst[2], s), s, join_lines = true)
 
     args = get_args(cst)
-    nest = length(args) > 0 && !(length(args) == 1 && unnestable_arg(args[1]))
+    nest = length(args) > 0 && !(length(args) == 1 && unnestable_node(args[1]))
 
     if nest
         add_node!(t, Placeholder(0), s)
@@ -1642,7 +1644,7 @@ function p_tupleh(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     t = FST(cst, nspaces(s))
 
     args = get_args(cst)
-    nest = length(args) > 0 && !(length(args) == 1 && unnestable_arg(args[1]))
+    nest = length(args) > 0 && !(length(args) == 1 && unnestable_node(args[1]))
 
     for (i, a) in enumerate(cst)
         n = if a.typ === CSTParser.BinaryOpCall && a[2].kind === Tokens.EQ
@@ -1674,7 +1676,7 @@ p_tupleh(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
 function p_braces(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     style = getstyle(ds)
     t = FST(cst, nspaces(s))
-    nest = length(cst) > 2 && !(length(cst) == 3 && unnestable_arg(cst[2]))
+    nest = length(cst) > 2 && !(length(cst) == 3 && unnestable_node(cst[2]))
 
     for (i, a) in enumerate(cst)
         n = pretty(style, a, s)
@@ -1701,7 +1703,7 @@ p_braces(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
 function p_bracescat(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     style = getstyle(ds)
     t = FST(cst, nspaces(s))
-    nest = length(cst) > 2 && !(length(cst) == 3 && unnestable_arg(cst[2]))
+    nest = length(cst) > 2 && !(length(cst) == 3 && unnestable_node(cst[2]))
 
     for (i, a) in enumerate(cst)
         n = pretty(style, a, s)
@@ -1729,7 +1731,7 @@ p_bracescat(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
 function p_vect(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     style = getstyle(ds)
     t = FST(cst, nspaces(s))
-    nest = length(cst) > 2 && !(length(cst) == 3 && unnestable_arg(cst[2]))
+    nest = length(cst) > 2 && !(length(cst) == 3 && unnestable_node(cst[2]))
 
     for (i, a) in enumerate(cst)
         n = pretty(style, a, s)
@@ -1844,8 +1846,9 @@ p_using(style::S, cst::CSTParser.EXPR, s::State) where {S<:AbstractStyle} =
 function p_ref(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     style = getstyle(ds)
     t = FST(cst, nspaces(s))
-    nest = length(cst) > 5 && !(length(cst) == 5 && unnestable_arg(cst[3]))
+    nest = length(cst) > 5 && !(length(cst) == 5 && unnestable_node(cst[3]))
     nospace = !s.opts.whitespace_ops_in_indices
+
     for (i, a) in enumerate(cst)
         if is_closer(a) && nest
             add_node!(t, TrailingComma(), s)
@@ -1875,7 +1878,7 @@ function p_vcat(ds::DefaultStyle, cst::CSTParser.EXPR, s::State)
     t = FST(cst, nspaces(s))
     st = cst.typ === CSTParser.Vcat ? 1 : 2
     args = get_args(cst)
-    nest = length(args) > 0 && !(length(args) == 1 && unnestable_arg(args[1]))
+    nest = length(args) > 0 && !(length(args) == 1 && unnestable_node(args[1]))
 
     for (i, a) in enumerate(cst)
         n = pretty(style, a, s)


Test patch:
diff --git a/test/default_style.jl b/test/default_style.jl
index f2f7698e..26ab389d 100644
--- a/test/default_style.jl
+++ b/test/default_style.jl
@@ -335,7 +335,11 @@
         end"""
         @test fmt(str) == str
 
-        str = "foo(args...)"
+        str_ = "foo(args...)"
+        str = """
+        foo(
+            args...,
+        )"""
         @test fmt(str, m = 1) == str
     end
 
@@ -757,7 +761,21 @@
         @test fmt(str) == str
 
         str = """
-        ignored_f(f) = f in (foo(@foo(foo(
+        ignored_f(f) = f in foo([{
+            GlobalRef(Base, :not_int),
+            GlobalRef(Core.Intrinsics, :not_int),
+            GlobalRef(Core, :(===)),
+            GlobalRef(Core, :apply_type),
+            GlobalRef(Core, :typeof),
+            GlobalRef(Core, :throw),
+            GlobalRef(Base, :kwerr),
+            GlobalRef(Core, :kwfunc),
+            GlobalRef(Core, :isdefined),
+        }])"""
+        @test fmt(str) == str
+
+        str = """
+        ignored_f(f) = f in foo(((
             GlobalRef(Base, :not_int),
             GlobalRef(Core.Intrinsics, :not_int),
             GlobalRef(Core, :(===)),
@@ -767,7 +785,7 @@
             GlobalRef(Base, :kwerr),
             GlobalRef(Core, :kwfunc),
             GlobalRef(Core, :isdefined),
-        ))))"""
+        )))"""
         @test fmt(str) == str
 
         str = "var = \"a_long_function_stringggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\""
@@ -1424,6 +1442,16 @@
         end"""
         @test fmt(str_) == str
 
+        str_ = """
+        begin
+        begin
+           throw(ErrorException(\"""An error occured formatting \$filename. :-(
+
+                                Please file an issue at https://github.com/domluna/JuliaFormatter.jl/issues
+                                with a link to a gist containing the contents of the file. A gist
+                                can be created at https://gist.github.com/.\"""))
+           end
+        end"""
         str = """
         begin
             begin
@@ -1434,17 +1462,22 @@
                                      can be created at https://gist.github.com/.\"""))
             end
         end"""
-        str_ = """
-        begin
-        begin
-           throw(ErrorException(\"""An error occured formatting \$filename. :-(
+        @test fmt(str_, 4, 120) == str
 
-                                Please file an issue at https://github.com/domluna/JuliaFormatter.jl/issues
-                                with a link to a gist containing the contents of the file. A gist
-                                can be created at https://gist.github.com/.\"""))
-           end
+        str = raw"""
+        begin
+            begin
+                throw(
+                    ErrorException(
+                        \"""An error occured formatting $filename. :-(
+
+                        Please file an issue at https://github.com/domluna/JuliaFormatter.jl/issues
+                        with a link to a gist containing the contents of the file. A gist
+                        can be created at https://gist.github.com/.\""",
+                    ),
+                )
+            end
         end"""
-        @test fmt(str_, 4, 200) == str
         @test fmt(str_, 4, 1) == str
 
         str = """
@@ -1473,14 +1506,24 @@
                      llvm2
                      \""")"""
         @test fmt(str, 4, 19) == str_
+
+        str_ = """
+        foo() = llvmcall(
+            \"""
+            llvm1
+            llvm2
+            \""",
+        )"""
         @test fmt(str, 4, 18) == str_
 
         str_ = """
         foo() =
-          llvmcall(\"""
-                   llvm1
-                   llvm2
-                   \""")"""
+          llvmcall(
+            \"""
+            llvm1
+            llvm2
+            \""",
+          )"""
         @test fmt(str, 2, 10) == str_
 
         str = """
@@ -1513,32 +1556,57 @@
         str_ = raw"""
         if free <
            min_space
-            throw(ErrorException(\"""
-            Free space: \$free Gb
-            Please make sure to have at least \$min_space Gb of free disk space
-            before downloading the $database_name database.
-            \"""))
+            throw(
+                ErrorException(
+                    \"""
+        Free space: \$free Gb
+        Please make sure to have at least \$min_space Gb of free disk space
+        before downloading the $database_name database.
+        \""",
+                ),
+            )
         end"""
         @test fmt(str) == str
         @test fmt(str, 4, 1) == str_
 
-        str = """foo(r"hello"x)"""
-        @test fmt(str, 4, 1) == str
+        str_ = """foo(r"hello"x)"""
+        str = """
+        foo(
+            r"hello"x,
+        )"""
+        @test fmt(str_, 4, 1) == str
 
-        str = """foo(r`hello`x)"""
-        @test fmt(str, 4, 1) == str
+        str_ = """foo(r`hello`x)"""
+        str = """
+        foo(
+            r`hello`x,
+        )"""
+        @test fmt(str_, 4, 1) == str
 
-        str = """foo(r\"""hello\"""x)"""
-        @test fmt(str, 4, 1) == str
+        str_ = """foo(r\"""hello\"""x)"""
+        str = """
+        foo(
+            r\"""hello\"""x,
+        )"""
+        @test fmt(str_, 4, 1) == str
 
-        str = """foo(r```hello```x)"""
-        @test fmt(str, 4, 1) == str
+        str_ = """foo(r```hello```x)"""
+        str = """foo(
+            r```hello```x,
+        )"""
+        @test fmt(str_, 4, 1) == str
 
-        str = """foo(\"""hello\""")"""
-        @test fmt(str, 4, 1) == str
+        str_ = """foo(\"""hello\""")"""
+        str = """foo(
+            \"""hello\""",
+        )"""
+        @test fmt(str_, 4, 1) == str
 
-        str = """foo(```hello```)"""
-        @test fmt(str, 4, 1) == str
+        str_ = """foo(```hello```)"""
+        str = """foo(
+            ```hello```,
+        )"""
+        @test fmt(str_, 4, 1) == str
     end
 
     @testset "comments" begin
@@ -2137,8 +2205,9 @@
                          e8
                      end
                  end"""
-        @test fmt("begin if cond1 e1; e2 elseif cond2 e3; e4 elseif cond3 e5;e6 else e7;e8  end end",) ==
-              str
+        @test fmt(
+            "begin if cond1 e1; e2 elseif cond2 e3; e4 elseif cond3 e5;e6 else e7;e8  end end",
+        ) == str
 
         str = """if cond1
                      e1
@@ -2580,6 +2649,42 @@
                :mesh_dim => Cint(3),)"""
         @test fmt(str_, 4, 80) == str
 
+        str = """
+        this_is_a_long_variable_name =
+             Dict{Symbol,Any}(
+                  :numberofpointattributes =>
+                       NAttributes,
+                  :numberofpointmtrs =>
+                       NMTr,
+                  :numberofcorners =>
+                       NSimplex,
+                  :firstnumber =>
+                       Cint(1),
+                  :mesh_dim =>
+                       Cint(3),
+             )"""
+        @test fmt(str_, 5, 23) == str
+
+        str = """
+        this_is_a_long_variable_name =
+             Dict{Symbol,Any}(
+                  :numberofpointattributes =>
+                       NAttributes,
+                  :numberofpointmtrs =>
+                       NMTr,
+                  :numberofcorners =>
+                       NSimplex,
+                  :firstnumber =>
+                       Cint(
+                            1,
+                       ),
+                  :mesh_dim =>
+                       Cint(
+                            3,
+                       ),
+             )"""
+        @test fmt(str_, 5, 22) == str
+
         str = """
         this_is_a_long_variable_name =
              Dict{
@@ -2593,9 +2698,13 @@
                   :numberofcorners =>
                        NSimplex,
                   :firstnumber =>
-                       Cint(1),
+                       Cint(
+                            1,
+                       ),
                   :mesh_dim =>
-                       Cint(3),
+                       Cint(
+                            3,
+                       ),
              )"""
         @test fmt(str_, 5, 1) == str
 
@@ -3222,14 +3331,23 @@
         # issue 56
         str_ = "a_long_function_name(Array{Float64,2}[[1.0], [0.5 0.5], [0.5 0.5; 0.5 0.5], [0.5 0.5; 0.5 0.5]])"
         str = """
-        a_long_function_name(Array{Float64,2}[
-            [1.0],
-            [0.5 0.5],
-            [0.5 0.5; 0.5 0.5],
-            [0.5 0.5; 0.5 0.5],
-        ])"""
+        a_long_function_name(
+            Array{Float64,2}[[1.0], [0.5 0.5], [0.5 0.5; 0.5 0.5], [0.5 0.5; 0.5 0.5]],
+        )"""
         @test fmt(str, 4, length(str)) == str_
         @test fmt(str_, 4, length(str_) - 1) == str
+        @test fmt(str_, 4, 79) == str
+
+        str = """
+        a_long_function_name(
+            Array{Float64,2}[
+                [1.0],
+                [0.5 0.5],
+                [0.5 0.5; 0.5 0.5],
+                [0.5 0.5; 0.5 0.5],
+            ],
+        )"""
+        @test fmt(str_, 4, 78) == str
 
         # unary op
         str_ = "[1, 1]'"
@@ -3561,8 +3679,9 @@
                 (file, i) => w
                 for (file, subject) in subjects
                 for
-                (i, w) in
-                enumerate(weightfn.(eachrow(subject.events)))
+                (i, w) in enumerate(
+                    weightfn.(eachrow(subject.events)),
+                )
             )
         end"""
         @test fmt(str_, 4, 50) == str
diff --git a/test/files/Docs.jl b/test/files/Docs.jl
index a64931cd..a6cfc8a3 100644
--- a/test/files/Docs.jl
+++ b/test/files/Docs.jl
@@ -360,24 +360,28 @@ end
 
 function keyworddoc(__source__, __module__, str, def::Base.BaseDocs.Keyword)
     @nospecialize str
-    docstr = esc(docexpr(
-        __source__,
-        __module__,
-        lazy_iterpolate(str),
-        metadata(__source__, __module__, def, false),
-    ),)
+    docstr = esc(
+        docexpr(
+            __source__,
+            __module__,
+            lazy_iterpolate(str),
+            metadata(__source__, __module__, def, false),
+        ),
+    )
     return :($setindex!($(keywords), $docstr, $(esc(quot(def.name)))); nothing)
 end
 
 function objectdoc(__source__, __module__, str, def, expr, sig = :(Union{}))
     @nospecialize str def expr sig
     binding = esc(bindingexpr(namify(expr)))
-    docstr = esc(docexpr(
-        __source__,
-        __module__,
-        lazy_iterpolate(str),
-        metadata(__source__, __module__, expr, false),
-    ),)
+    docstr = esc(
+        docexpr(
+            __source__,
+            __module__,
+            lazy_iterpolate(str),
+            metadata(__source__, __module__, expr, false),
+        ),
+    )
     # Note: we want to avoid introducing line number nodes here (issue #24468)
     return Expr(:block, esc(def), :($(doc!)($__module__, $binding, $docstr, $(esc(sig)))))
 end
diff --git a/test/files/PProf.jl b/test/files/PProf.jl
index d261cc6c..cbe3f461 100644
--- a/test/files/PProf.jl
+++ b/test/files/PProf.jl
@@ -18,7 +18,9 @@ clear
 # Load in `deps.jl`, complaining if it does not exist
 const depsjl_path = joinpath(@__DIR__, "..", "deps", "deps.jl")
 if !isfile(depsjl_path)
-    error("PProf not installed properly, run Pkg.build(\"PProf\"), restart Julia and try again",)
+    error(
+        "PProf not installed properly, run Pkg.build(\"PProf\"), restart Julia and try again",
+    )
 end
 include(depsjl_path)
 
diff --git a/test/files/ValidationManifold.jl b/test/files/ValidationManifold.jl
index 86b97819..0e7cf976 100644
--- a/test/files/ValidationManifold.jl
+++ b/test/files/ValidationManifold.jl
@@ -148,12 +148,20 @@ function get_basis(M::ValidationManifold, p, B::AbstractBasis; kwargs...)
     bvectors = get_vectors(M, p, Ξ)
     N = length(bvectors)
     if N != manifold_dimension(M.manifold)
-        throw(ErrorException("For a basis of the tangent space at $(p) of $(M.manifold), $(manifold_dimension(M)) vectors are required, but get_basis $(B) computed $(N)"))
+        throw(
+            ErrorException(
+                "For a basis of the tangent space at $(p) of $(M.manifold), $(manifold_dimension(M)) vectors are required, but get_basis $(B) computed $(N)",
+            ),
+        )
     end
     # check that the vectors are linearly independent\
     bv_rank = rank(reduce(hcat, bvectors))
     if N != bv_rank
-        throw(ErrorException("For a basis of the tangent space at $(p) of $(M.manifold), $(manifold_dimension(M)) linearly independent vectors are required, but get_basis $(B) computed $(bv_rank)"))
+        throw(
+            ErrorException(
+                "For a basis of the tangent space at $(p) of $(M.manifold), $(manifold_dimension(M)) linearly independent vectors are required, but get_basis $(B) computed $(bv_rank)",
+            ),
+        )
     end
     map(X -> is_tangent_vector(M, p, X, true; kwargs...), bvectors)
     return Ξ
@@ -172,7 +180,11 @@ function get_basis(
         for j = (i+1):N
             dot_val = real(inner(M, p, bvectors[i], bvectors[j]))
             if !isapprox(dot_val, 0; atol = eps(eltype(p)))
-                throw(ArgumentError("vectors number $i and $j are not orthonormal (inner product = $dot_val)"))
+                throw(
+                    ArgumentError(
+                        "vectors number $i and $j are not orthonormal (inner product = $dot_val)",
+                    ),
+                )
             end
         end
     end
diff --git a/test/files/parse_nlp.jl b/test/files/parse_nlp.jl
index 23281555..d69cfa11 100644
--- a/test/files/parse_nlp.jl
+++ b/test/files/parse_nlp.jl
@@ -12,7 +12,9 @@ function _let_code_block(ex::Expr)
 end
 
 function _error_curly(x)
-    Base.error("The curly syntax (sum{},prod{},norm2{}) is no longer supported. Expression: $x.")
+    Base.error(
+        "The curly syntax (sum{},prod{},norm2{}) is no longer supported. Expression: $x.",
+    )
 end
 
 # generates code which converts an expression into a NodeData array (tape)
@@ -266,7 +268,9 @@ function _parse_NL_expr_runtime(m::Model, x::NonlinearParameter, tape, parent, v
 end
 
 function _parse_NL_expr_runtime(m::Model, x::AbstractArray, tape, parent, values)
-    error("Unexpected array $x in nonlinear expression. Nonlinear expressions may contain only scalar expressions.")
+    error(
+        "Unexpected array $x in nonlinear expression. Nonlinear expressions may contain only scalar expressions.",
+    )
 end
 
 function _parse_NL_expr_runtime(m::Model, x::GenericQuadExpr, tape, parent, values)
@@ -367,7 +371,9 @@ _NonlinearExprData(m::Model, ex) = _NonlinearExprData(m, :($ex + 0))
 # 2) VariableRef doesn't match the model
 function _check_expr(m::Model, ex::Expr)
     if ex.head == :ref # if we have x[1] already in there, something is wrong
-        error("Unrecognized expression $ex. JuMP variable objects and input coefficients should be spliced directly into expressions.")
+        error(
+            "Unrecognized expression $ex. JuMP variable objects and input coefficients should be spliced directly into expressions.",
+        )
     end
     for e in ex.args
         _check_expr(m, e)
diff --git a/test/issues.jl b/test/issues.jl
index 4d6f2eeb..a546403c 100644
--- a/test/issues.jl
+++ b/test/issues.jl
@@ -251,26 +251,15 @@
             nothing
         end"""
         str = """
-        function f(args...)
-
-            next!(s.progress;
-            # comment
-        )
-            nothing
-        end"""
-        @test fmt(str_) == str
-
-        # NOTE: when this passes delete the above test
-        str = """
         function f(args...)
 
             next!(
-                s.progress;
+                s.progress,
                 # comment
             )
             nothing
         end"""
-        @test_broken fmt(str_) == str
+        @test fmt(str_) == str
     end
 
     @testset "issue #189" begin
diff --git a/test/runtests.jl b/test/runtests.jl
index 4789ccb3..0714870a 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -35,10 +35,6 @@ function run_nest(text::String; opts = Options(), style = DefaultStyle())
 end
 run_nest(text::String, margin::Int) = run_nest(text, opts = Options(margin = margin))
 
-function fmt(str, i, m; kwargs...)
-    return fmt(str; kwargs..., i = i, m = m)
-end
-
 yasfmt1(str) = fmt1(str; style = YASStyle(), options(DefaultStyle())...)
 yasfmt(str, i = 4, m = 80; kwargs...) = fmt(str, i, m; style = YASStyle(), kwargs...)