diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index ef168587..7d1ae4c1 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -1,3 +1,4 @@ remove_extra_newlines = true always_for_in = true conditional_to_if = true +separate_kwargs_with_semicolon = true diff --git a/docs/make.jl b/docs/make.jl index 94f7aa0d..950dfea3 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,8 +1,8 @@ using Documenter, JuliaFormatter -makedocs( +makedocs(; sitename = "JuliaFormatter", - format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"), + format = Documenter.HTML(; prettyurls = get(ENV, "CI", nothing) == "true"), modules = [JuliaFormatter], pages = [ "Introduction" => "index.md", @@ -20,4 +20,4 @@ makedocs( warnonly = true, ) -deploydocs(repo = "github.com/domluna/JuliaFormatter.jl.git", push_preview = true) +deploydocs(; repo = "github.com/domluna/JuliaFormatter.jl.git", push_preview = true) diff --git a/src/align.jl b/src/align.jl index 5d5a98ca..34cf25f3 100644 --- a/src/align.jl +++ b/src/align.jl @@ -336,7 +336,7 @@ function align_conditional!(fst::FST) # the placeholder would be i+1 if not for a possible inline comment nind = findnext(n -> n.typ === PLACEHOLDER, nodes, ind + 1)::Int if nodes[nind+1].startline != nodes[nind].startline - nodes[nind] = Newline(nest_behavior = AlwaysNest) + nodes[nind] = Newline(; nest_behavior = AlwaysNest) end if colon_len !== nothing diff --git a/src/fst.jl b/src/fst.jl index 02dc2303..d3dace14 100644 --- a/src/fst.jl +++ b/src/fst.jl @@ -1079,7 +1079,7 @@ function add_node!( end if nt !== PLACEHOLDER - add_node!(t, Newline(nest_behavior = AlwaysNest), s) + add_node!(t, Newline(; nest_behavior = AlwaysNest), s) elseif hascomment(s.doc, current_line) && nt === PLACEHOLDER # swap PLACEHOLDER (will be NEWLINE) with INLINECOMMENT node idx = length(tnodes::Vector{FST}) @@ -1088,13 +1088,13 @@ function add_node!( if nest add_node!(t, Notcode(notcode_startline, notcode_endline), s) - add_node!(t, Newline(nest_behavior = AlwaysNest), s) + add_node!(t, Newline(; nest_behavior = AlwaysNest), s) end elseif !join_lines if hascomment(s.doc, current_line) && current_line != n.startline add_node!(t, InlineComment(current_line), s) end - add_node!(t, Newline(nest_behavior = AlwaysNest), s) + add_node!(t, Newline(; nest_behavior = AlwaysNest), s) elseif nt === PLACEHOLDER && current_line != n.startline && hascomment(s.doc, current_line) @@ -1109,7 +1109,7 @@ function add_node!( # rely on the whitespace tracked for the inline comment tnodes[end] = Whitespace(0) add_node!(t, InlineComment(current_line), s) - add_node!(t, Newline(nest_behavior = AlwaysNest), s) + add_node!(t, Newline(; nest_behavior = AlwaysNest), s) end end diff --git a/src/nest_utils.jl b/src/nest_utils.jl index 14368d81..26876708 100644 --- a/src/nest_utils.jl +++ b/src/nest_utils.jl @@ -175,7 +175,7 @@ function nest_if_over_margin!( if margin > s.opts.margin || (idx < length(fst.nodes::Vector) && is_comment(fst[idx+1])) || (idx > 1 && is_comment(fst[idx-1])) - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) s.line_offset = fst.indent return true end @@ -265,7 +265,7 @@ function find_optimal_nest_placeholders( fst, g, start_line_offset, - max_margin, + max_margin; last_group = i == length(placeholder_groups), ) push!(optimal_placeholders, optinds...) diff --git a/src/passes.jl b/src/passes.jl index af860786..12fde33c 100644 --- a/src/passes.jl +++ b/src/passes.jl @@ -22,7 +22,7 @@ function flatten_binaryopcall(fst::FST; top = true) end if lhs_same_op - append!(nodes, flatten_binaryopcall(lhs, top = false)) + append!(nodes, flatten_binaryopcall(lhs; top = false)) else flatten_fst!(lhs) push!(nodes, lhs) @@ -31,7 +31,7 @@ function flatten_binaryopcall(fst::FST; top = true) append!(nodes, fst[2:(idx-1)]) if rhs_same_op - append!(nodes, flatten_binaryopcall(rhs, top = false)) + append!(nodes, flatten_binaryopcall(rhs; top = false)) else flatten_fst!(rhs) push!(nodes, rhs) @@ -185,12 +185,12 @@ function import_to_usings(fst::FST, s::State) add_node!(use, FST(KEYWORD, -1, sl, el, "using"), s) add_node!(use, Whitespace(1), s) - add_node!(use, n, s, join_lines = true) + add_node!(use, n, s; join_lines = true) colon = FST(OPERATOR, -1, sl, el, ":") colon.metadata = Metadata(K"::", false) - add_node!(use, colon, s, join_lines = true) + add_node!(use, colon, s; join_lines = true) add_node!(use, Whitespace(1), s) - add_node!(use, n[end], s, join_lines = true) + add_node!(use, n[end], s; join_lines = true) push!(usings, use) end @@ -215,12 +215,12 @@ function annotate_typefields_with_any!(fst::FST, s::State) line_offset = n.line_offset + length(n) op = FST(OPERATOR, line_offset, n.startline, n.endline, "::") op.metadata = Metadata(K"::", false) - add_node!(nn, op, s, join_lines = true) + add_node!(nn, op, s; join_lines = true) line_offset += 2 add_node!( nn, FST(IDENTIFIER, line_offset, n.startline, n.endline, "Any"), - s, + s; join_lines = true, ) fst[i] = nn @@ -286,13 +286,13 @@ function short_to_long_function_def!( # func(a) # OR # func(a) where T - add_node!(funcdef, fst[1], s, join_lines = true) + add_node!(funcdef, fst[1], s; join_lines = true) # body # s.opts.always_use_return && prepend_return!(fst[end], s) if fst[end].typ === Block - add_node!(funcdef, fst[end], s, max_padding = s.opts.indent) + add_node!(funcdef, fst[end], s; max_padding = s.opts.indent) elseif fst[end].typ === Begin # case where body is wrapped in a `begin` block # which becomes superfluous when converted to a @@ -308,7 +308,7 @@ function short_to_long_function_def!( idx === nothing && return false bnode = fst[end][idx] add_indent!(bnode, s, -s.opts.indent) - add_node!(funcdef, bnode, s, max_padding = s.opts.indent) + add_node!(funcdef, bnode, s; max_padding = s.opts.indent) else # ``` # function @@ -320,7 +320,7 @@ function short_to_long_function_def!( # a `Block` node ensures the indent is correct. bl = FST(Block, fst[end].indent) add_node!(bl, fst[end], s) - add_node!(funcdef, bl, s, max_padding = s.opts.indent) + add_node!(funcdef, bl, s; max_padding = s.opts.indent) end add_indent!(funcdef[end], s, s.opts.indent) @@ -461,17 +461,17 @@ function binaryop_to_whereop!(fst::FST, s::State) if n.typ === Where break end - add_node!(binop, n, s, join_lines = true) + add_node!(binop, n, s; join_lines = true) end # # foo(a::A)::R gets the "R" - add_node!(binop, oldwhereop[1], s, join_lines = true) + add_node!(binop, oldwhereop[1], s; join_lines = true) whereop = FST(Where, fst[1].indent) add_node!(whereop, binop, s) # "foo(a::A)::R where A" for n in oldwhereop[2:end] - add_node!(whereop, n, s, join_lines = true) + add_node!(whereop, n, s; join_lines = true) end fst[1] = whereop @@ -592,9 +592,9 @@ end function conditional_to_if_block!(fst::FST, s::State, top::Bool) t = FST(If, fst.indent) kw = FST(KEYWORD, -1, fst.startline, fst.startline, top ? "if" : "elseif") - add_node!(t, kw, s, max_padding = 0) - add_node!(t, Whitespace(1), s, join_lines = true) - add_node!(t, fst[1], s, join_lines = true) + add_node!(t, kw, s; max_padding = 0) + add_node!(t, Whitespace(1), s; join_lines = true) + add_node!(t, fst[1], s; join_lines = true) nodes = fst.nodes::Vector{FST} idx1 = findfirst(n -> n.typ === OPERATOR && n.val == "?", nodes)::Int @@ -610,7 +610,7 @@ function conditional_to_if_block!(fst::FST, s::State, top::Bool) end add_node!(block1, n, s) end - add_node!(t, block1, s, max_padding = s.opts.indent) + add_node!(t, block1, s; max_padding = s.opts.indent) block2 = FST(Block, fst.indent) padding = 0 @@ -620,14 +620,14 @@ function conditional_to_if_block!(fst::FST, s::State, top::Bool) block2.indent += s.opts.indent padding = s.opts.indent kw = FST(KEYWORD, 0, 0, -1, "else") - add_node!(t, kw, s, max_padding = 0) + add_node!(t, kw, s; max_padding = 0) end add_node!(block2, fst[end], s) - add_node!(t, block2, s, max_padding = 0) + add_node!(t, block2, s; max_padding = 0) if top kw = FST(KEYWORD, 0, 0, -1, "end") - add_node!(t, kw, s, max_padding = 0) + add_node!(t, kw, s; max_padding = 0) end fst.typ = t.typ @@ -730,8 +730,8 @@ function _short_circuit_to_if!(fst::FST, s::State) # change it into an if t = FST(If, fst.indent) kw = FST(KEYWORD, -1, fst.startline, fst.startline, "if") - add_node!(t, kw, s, max_padding = 0) - add_node!(t, Whitespace(1), s, join_lines = true) + add_node!(t, kw, s; max_padding = 0) + add_node!(t, Whitespace(1), s; join_lines = true) nodes = fst.nodes::Vector{FST} idx = findlast(n -> n.typ === OPERATOR && (n.val == "||" || n.val == "&&"), nodes)::Int @@ -748,45 +748,45 @@ function _short_circuit_to_if!(fst::FST, s::State) add_node!( brackets, FST(PUNCTUATION, -1, fst.startline, fst.startline, "("), - s, + s; join_lines = true, ) add_node!(brackets, Placeholder(0), s) # inner lhs = FST(Chain, fst.indent) for n in nodes[1:(idx-1)] - add_node!(lhs, n, s, join_lines = true) + add_node!(lhs, n, s; join_lines = true) end # remove extra ws if lhs[end].typ === WHITESPACE lhs[end] = Whitespace(0) end - add_node!(brackets, lhs, s, join_lines = true) + add_node!(brackets, lhs, s; join_lines = true) add_node!(brackets, Placeholder(0), s) add_node!( brackets, FST(PUNCTUATION, -1, nodes[idx-2].startline, nodes[idx-2].startline, ")"), - s, + s; join_lines = true, ) - add_node!(call, brackets, s, join_lines = true) + add_node!(call, brackets, s; join_lines = true) else - add_node!(call, fst[1], s, join_lines = true) + add_node!(call, fst[1], s; join_lines = true) end - add_node!(t, call, s, join_lines = true) + add_node!(t, call, s; join_lines = true) else # from idx-1 go backwards until we find a node that's not a lhs = FST(Chain, fst.indent) for n in nodes[1:(idx-1)] - add_node!(lhs, n, s, join_lines = true) + add_node!(lhs, n, s; join_lines = true) end # remove extra ws if lhs[end].typ === WHITESPACE lhs[end] = Whitespace(0) end - add_node!(t, lhs, s, join_lines = true) + add_node!(t, lhs, s; join_lines = true) end block1 = FST(Block, fst.indent + s.opts.indent) @@ -799,10 +799,10 @@ function _short_circuit_to_if!(fst::FST, s::State) end add_node!(block1, n, s) end - add_node!(t, block1, s, max_padding = s.opts.indent) + add_node!(t, block1, s; max_padding = s.opts.indent) kw = FST(KEYWORD, 0, 0, -1, "end") - add_node!(t, kw, s, max_padding = 0) + add_node!(t, kw, s; max_padding = 0) fst.typ = t.typ fst.nodes = t.nodes diff --git a/src/print.jl b/src/print.jl index 9eef4df5..2411c6c7 100644 --- a/src/print.jl +++ b/src/print.jl @@ -94,7 +94,7 @@ function print_tree(io::IOBuffer, fst::FST, s::State) if (fst.typ === Binary || fst.typ === Conditional || fst.typ === ModuleN) notcode_indent = fst.indent end - print_tree(io, fst.nodes::Vector{FST}, s, fst.indent, notcode_indent = notcode_indent) + print_tree(io, fst.nodes::Vector{FST}, s, fst.indent; notcode_indent = notcode_indent) end function print_tree( diff --git a/src/styles/blue/nest.jl b/src/styles/blue/nest.jl index 118bb8bf..0293bb17 100644 --- a/src/styles/blue/nest.jl +++ b/src/styles/blue/nest.jl @@ -72,7 +72,7 @@ function n_tuple!( if n.typ === NEWLINE s.line_offset = fst.indent elseif (i == fidx || i == lidx) && !src_diff_line && nest_to_oneline - fst[i] = Newline(length = n.len) + fst[i] = Newline(; length = n.len) s.line_offset = fst.indent elseif n.typ === PLACEHOLDER if src_diff_line @@ -92,7 +92,7 @@ function n_tuple!( end end elseif !nest_to_oneline - fst[i] = Newline(length = n.len) + fst[i] = Newline(; length = n.len) s.line_offset = fst.indent else nest!(style, n, s, lineage) diff --git a/src/styles/blue/pretty.jl b/src/styles/blue/pretty.jl index 7dae9199..7a283952 100644 --- a/src/styles/blue/pretty.jl +++ b/src/styles/blue/pretty.jl @@ -94,6 +94,6 @@ function p_return( end add_node!(t, Whitespace(1), s) no = FST(KEYWORD, -1, t.endline, t.endline, "nothing") - add_node!(t, no, s, join_lines = true) + add_node!(t, no, s; join_lines = true) t end diff --git a/src/styles/default/nest.jl b/src/styles/default/nest.jl index 1c288fa8..c1663ead 100644 --- a/src/styles/default/nest.jl +++ b/src/styles/default/nest.jl @@ -255,7 +255,7 @@ function n_using!( if idx !== nothing && (line_margin > s.opts.margin || must_nest(fst)) if can_nest(fst) if fst.indent + sum(length.(fst[(idx+1):end])) <= s.opts.margin - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) walk(increment_line_offset!, fst, s) return nested end @@ -269,7 +269,7 @@ function n_using!( si = findnext(n -> n.typ === PLACEHOLDER, nodes, i + 1) nested |= nest_if_over_margin!(style, fst, s, i, lineage; stop_idx = si) else - fst[i] = Newline(length = n.len) + fst[i] = Newline(; length = n.len) s.line_offset = fst.indent end else @@ -353,7 +353,7 @@ function n_tuple!( end end else - fst[i] = Newline(length = n.len) + fst[i] = Newline(; length = n.len) s.line_offset = fst.indent end elseif n.typ === TRAILINGCOMMA @@ -502,11 +502,11 @@ function _n_comprehension!( if closer && (line_margin > s.opts.margin || must_nest(fst)) idx = findfirst(n -> n.typ === PLACEHOLDER, nodes) if idx !== nothing - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) end idx = findlast(n -> n.typ === PLACEHOLDER, nodes) if idx !== nothing - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) end add_indent!(fst, s, s.opts.indent) @@ -519,7 +519,7 @@ function _n_comprehension!( s.line_offset = fst.indent elseif n.typ === PLACEHOLDER if must_nest(fst) - fst[i] = Newline(length = n.len) + fst[i] = Newline(; length = n.len) s.line_offset = fst.indent else nest_if_over_margin!(style, fst, s, i, lineage) @@ -577,14 +577,14 @@ function n_generator!( end for (i, idx) in enumerate(phs) if i == 1 - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) else nidx = phs[i-1] l1 = sum(length.(fst[1:(idx-1)])) l2 = sum(length.(fst[idx:(nidx-1)])) width = line_offset + l1 + l2 if must_nest(fst) || width > s.opts.margin - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) end end end @@ -608,7 +608,7 @@ function n_generator!( i in phs # +1 for newline to whitespace conversion width = s.line_offset + 1 - w, _ = length_to(fst, (NEWLINE,), start = i + 1) + w, _ = length_to(fst, (NEWLINE,); start = i + 1) width += w if width <= s.opts.margin fst[i] = Whitespace(1) @@ -675,7 +675,7 @@ function n_whereopcall!( end nest!(style, n, s, lineage) elseif n.typ === PLACEHOLDER && over - fst[i+1] = Newline(length = length(n)) + fst[i+1] = Newline(; length = length(n)) s.line_offset = fst.indent elseif n.typ === TRAILINGCOMMA && over n.val = "," @@ -735,14 +735,14 @@ function n_conditionalopcall!( end for (i, idx) in enumerate(phs) if i == 1 - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) else nidx = phs[i-1] l1 = sum(length.(fst[1:(idx-1)])) l2 = sum(length.(fst[idx:(nidx-1)])) width = line_offset + l1 + l2 if must_nest(fst) || width > s.opts.margin - fst[idx] = Newline(length = fst[idx].len) + fst[idx] = Newline(; length = fst[idx].len) end end end @@ -835,7 +835,7 @@ function n_binaryopcall!( (line_margin > s.opts.margin || must_nest(fst) || must_nest(rhs) || src_diff_line) i1 = idxs[1] i2 = idxs[2] - fst[i1] = Newline(length = fst[i1].len) + fst[i1] = Newline(; length = fst[i1].len) nested = true indent_nest = @@ -890,7 +890,7 @@ function n_binaryopcall!( rhs.typ === Conditional line_margin += length(fst[end]) elseif rhs.typ === Do && is_iterable(rhs[1]) - rw, _ = length_to(fst, (NEWLINE,), start = i2 + 1) + rw, _ = length_to(fst, (NEWLINE,); start = i2 + 1) line_margin += rw elseif is_block(rhs) idx = findfirst(n -> n.typ === NEWLINE, rhs.nodes) @@ -900,7 +900,7 @@ function n_binaryopcall!( line_margin += sum(length.(rhs[1:(idx-1)])) end else - rw, _ = length_to(fst, (NEWLINE,), start = i2 + 1) + rw, _ = length_to(fst, (NEWLINE,); start = i2 + 1) line_margin += rw end @@ -1040,13 +1040,13 @@ function n_block!( ) nest_if_over_margin!(style, fst, s, i, lineage; stop_idx = si) elseif has_nl - fst[i] = Newline(length = n.len) + fst[i] = Newline(; length = n.len) s.line_offset = fst.indent else nest!(style, n, s, lineage) end else - fst[i] = Newline(length = n.len) + fst[i] = Newline(; length = n.len) s.line_offset = fst.indent has_nl = true end diff --git a/src/styles/default/pretty.jl b/src/styles/default/pretty.jl index 8b06ca09..c92143e4 100644 --- a/src/styles/default/pretty.jl +++ b/src/styles/default/pretty.jl @@ -331,7 +331,7 @@ function p_juxtapose( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end return t @@ -349,7 +349,7 @@ function p_continue( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end return t @@ -367,7 +367,7 @@ function p_break( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end return t @@ -386,7 +386,7 @@ function p_inert( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end return t @@ -404,7 +404,7 @@ function p_macrostr( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end return t @@ -561,12 +561,12 @@ function p_globalrefdoc( if i == 1 add_node!( t, - pretty(style, c, s, newctx(ctx, from_docstring = true), lineage), - s, + pretty(style, c, s, newctx(ctx; from_docstring = true), lineage), + s; max_padding = 0, ) elseif i == length(childs) - add_node!(t, pretty(style, c, s, ctx, lineage), s, max_padding = 0) + add_node!(t, pretty(style, c, s, ctx, lineage), s; max_padding = 0) else add_node!(t, pretty(style, c, s, ctx, lineage), s) end @@ -607,15 +607,15 @@ function p_macrocall( for (i, a) in enumerate(childs) n = pretty(style, a, s, ctx, lineage)::FST if JuliaSyntax.is_macro_name(a) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"(" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(a) === K")" nest && add_node!(t, Placeholder(0), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K")") add_node!(t, Placeholder(1), s) end @@ -636,10 +636,10 @@ function p_macrocall( add_node!(t, n, s; join_lines, max_padding) else if has_closer - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else padding = is_block(n) ? 0 : -1 - add_node!(t, n, s, join_lines = true, max_padding = padding) + add_node!(t, n, s; join_lines = true, max_padding = padding) end end end @@ -684,39 +684,39 @@ function p_block( if from_quote && !single_line if kind(a) in KSet"; ) (" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K")") add_node!(t, Whitespace(1), s) end elseif JuliaSyntax.is_whitespace(a) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif before_first_arg - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) before_first_arg = false else - add_node!(t, n, s, max_padding = 0) + add_node!(t, n, s; max_padding = 0) end elseif single_line if kind(a) in KSet", ;" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) add_node!(t, Placeholder(1), s) else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end else if kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if join_body && needs_placeholder(childs, i + 1, K")") add_node!(t, Placeholder(1), s) end elseif kind(a) === K";" continue elseif join_body - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else - add_node!(t, n, s, max_padding = 0) + add_node!(t, n, s; max_padding = 0) end end end @@ -742,13 +742,13 @@ function p_block( end n = pretty(style, a, s, ctx, lineage) if i < length(nodes) && kind(a) === K"," && is_punc(nodes[i+1]) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," && i != length(nodes) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K";" continue else - add_node!(t, n, s, max_padding = 0) + add_node!(t, n, s; max_padding = 0) end end t @@ -767,7 +767,7 @@ function p_abstract( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) if !JuliaSyntax.is_whitespace(c) && kind(c) !== K"end" add_node!(t, Whitespace(1), s) end @@ -788,7 +788,7 @@ function p_primitive( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) if !JuliaSyntax.is_whitespace(c) && kind(c) !== K"end" add_node!(t, Whitespace(1), s) end @@ -808,7 +808,7 @@ function p_var( !haschildren(cst) && return t for c in children(cst) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end t end @@ -837,12 +837,12 @@ function p_functiondef( if s.opts.join_lines_based_on_source && !block_has_contents join_lines = t.endline == n.startline join_lines && (add_node!(t, Whitespace(1), s)) - add_node!(t, n, s, join_lines = join_lines) + add_node!(t, n, s; join_lines = join_lines) elseif block_has_contents add_node!(t, n, s) else add_node!(t, Whitespace(1), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end elseif kind(c) === K"block" && haschildren(c) block_has_contents = @@ -857,9 +857,9 @@ function p_functiondef( s.indent -= s.opts.indent elseif kind(c) === K"call" n = pretty(style, c, s, newctx(ctx; can_separate_kwargs = false), lineage) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end end t.metadata = Metadata(kind(cst), false, false, false, false, true, false) @@ -902,12 +902,12 @@ function p_struct( if s.opts.join_lines_based_on_source && !block_has_contents join_lines = t.endline == n.startline join_lines && (add_node!(t, Whitespace(1), s)) - add_node!(t, n, s, join_lines = join_lines) + add_node!(t, n, s; join_lines = join_lines) elseif block_has_contents add_node!(t, n, s) else add_node!(t, Whitespace(1), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end elseif kind(c) === K"block" && haschildren(c) block_has_contents = @@ -917,10 +917,10 @@ function p_struct( if s.opts.annotate_untyped_fields_with_any annotate_typefields_with_any!(n, s) end - add_node!(t, n, s, max_padding = s.opts.indent) + add_node!(t, n, s; max_padding = s.opts.indent) s.indent -= s.opts.indent else - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end end t @@ -950,12 +950,12 @@ function p_mutable( if s.opts.join_lines_based_on_source && !block_has_contents join_lines = t.endline == n.startline join_lines && (add_node!(t, Whitespace(1), s)) - add_node!(t, n, s, join_lines = join_lines) + add_node!(t, n, s; join_lines = join_lines) elseif block_has_contents add_node!(t, n, s) else add_node!(t, Whitespace(1), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end elseif kind(c) === K"block" && haschildren(c) block_has_contents = @@ -965,10 +965,10 @@ function p_mutable( if s.opts.annotate_untyped_fields_with_any annotate_typefields_with_any!(n, s) end - add_node!(t, n, s, max_padding = s.opts.indent) + add_node!(t, n, s; max_padding = s.opts.indent) s.indent -= s.opts.indent else - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end end t @@ -1001,12 +1001,12 @@ function p_module( if s.opts.join_lines_based_on_source && !block_has_contents join_lines = t.endline == n.startline join_lines && (add_node!(t, Whitespace(1), s)) - add_node!(t, n, s, join_lines = join_lines) + add_node!(t, n, s; join_lines = join_lines) elseif block_has_contents add_node!(t, n, s) else add_node!(t, Whitespace(1), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end elseif kind(c) === K"block" && haschildren(c) block_has_contents = @@ -1026,13 +1026,13 @@ function p_module( add_node!(t, n, s; max_padding = s.opts.indent) s.indent -= s.opts.indent else - add_node!(t, n, s, max_padding = 0) + add_node!(t, n, s; max_padding = 0) end else add_node!( t, pretty(style, c, s, newctx(ctx; from_module = true), lineage), - s, + s; join_lines = true, ) end @@ -1083,7 +1083,7 @@ function p_const( elseif !JuliaSyntax.is_whitespace(c) && JuliaSyntax.is_keyword(c) && haschildren(c) add_node!(t, Whitespace(1), s) end - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end t end @@ -1138,9 +1138,9 @@ function p_toplevel( for a in children(cst) n = pretty(style, a, s, ctx, lineage) if kind(a) === K";" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else - add_node!(t, n, s, max_padding = 0) + add_node!(t, n, s; max_padding = 0) end end t @@ -1166,14 +1166,14 @@ function p_begin( pretty(style, c, s, ctx, lineage) end add_node!(t, Whitespace(1), s) - add_node!(t, pretty(style, cst[end], s), s, join_lines = true) + add_node!(t, pretty(style, cst[end], s), s; join_lines = true) else push!(lineage, (K"block", false, false)) s.indent += s.opts.indent add_node!( t, p_block(style, childs[2:(end-1)], s, ctx, lineage), - s, + s; max_padding = s.opts.indent, ) s.indent -= s.opts.indent @@ -1276,7 +1276,7 @@ function p_let( newctx(ctx; join_body = true, from_let = true), lineage, ), - s, + s; join_lines = true, ) else @@ -1289,7 +1289,7 @@ function p_let( newctx(ctx; ignore_single_line = true, from_let = true), lineage, ), - s, + s; max_padding = s.opts.indent, ) if has_let_args && (t.nodes::Vector{FST})[end-2].typ !== NOTCODE @@ -1311,7 +1311,7 @@ function p_let( add_node!( t, pretty(style, c, s, newctx(ctx; from_let = true), lineage), - s, + s; join_lines = true, ) end @@ -1366,7 +1366,7 @@ function p_for( if kind(cst) === K"for" eq_to_in_normalization!(n, s.opts.always_for_in, s.opts.for_in_replacement) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end @@ -1388,7 +1388,7 @@ function p_cartesian_iterator( for (i, c) in enumerate(childs) n = pretty(style, c, s, ctx, lineage) if kind(c) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K")") add_node!(t, Placeholder(1), s) end @@ -1396,9 +1396,9 @@ function p_cartesian_iterator( if ctx.from_for eq_to_in_normalization!(n, s.opts.always_for_in, s.opts.for_in_replacement) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end @@ -1434,7 +1434,7 @@ function p_do( for (i, c) in enumerate(childs) if kind(c) === K"do" && !haschildren(c) add_node!(t, Whitespace(1), s) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) if !next_node_is(K"NewlineWs", childs[i+1]) add_node!(t, Whitespace(1), s) end @@ -1446,10 +1446,10 @@ function p_do( if s.opts.always_use_return prepend_return!(n, s) end - add_node!(t, n, s, max_padding = s.opts.indent) + add_node!(t, n, s; max_padding = s.opts.indent) s.indent -= s.opts.indent else - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end end t @@ -1480,7 +1480,7 @@ function p_try( if kind(c) in KSet"catch finally" s.indent -= s.opts.indent end - add_node!(t, pretty(style, c, s, ctx, lineage), s, max_padding = 0) + add_node!(t, pretty(style, c, s, ctx, lineage), s; max_padding = 0) else len = length(t) n = pretty(style, c, s, ctx, lineage) @@ -1495,7 +1495,7 @@ function p_try( add_node!( t, pretty(style, c, s, newctx(ctx; ignore_single_line = true), lineage), - s, + s; max_padding = s.opts.indent, ) elseif !JuliaSyntax.is_whitespace(c) @@ -1503,7 +1503,7 @@ function p_try( if !(kind(cst) === K"catch" && any(n -> kind(n) === K"false", childs)) add_node!(t, Whitespace(1), s) end - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) else add_node!(t, pretty(style, c, s, ctx, lineage), s) end @@ -1526,7 +1526,7 @@ function p_if( for c in children(cst) if kind(c) in KSet"if elseif else" if !haschildren(c) - add_node!(t, pretty(style, c, s, ctx, lineage), s, max_padding = 0) + add_node!(t, pretty(style, c, s, ctx, lineage), s; max_padding = 0) else len = length(t) n = pretty(style, c, s, ctx, lineage) @@ -1540,13 +1540,13 @@ function p_if( add_node!( t, pretty(style, c, s, newctx(ctx; ignore_single_line = true), lineage), - s, + s; max_padding = s.opts.indent, ) s.indent -= s.opts.indent elseif !JuliaSyntax.is_whitespace(c) add_node!(t, Whitespace(1), s) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) else add_node!(t, pretty(style, c, s, ctx, lineage), s) end @@ -1598,7 +1598,7 @@ function p_kw( for c in children(cst) if kind(c) === K"=" && s.opts.whitespace_in_kwargs add_node!(t, Whitespace(1), s) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) add_node!(t, Whitespace(1), s) else n = pretty(style, c, s, ctx, lineage) @@ -1607,18 +1607,18 @@ function p_kw( add_node!( t, FST(PUNCTUATION, -1, n.startline, n.startline, "("), - s, + s; join_lines = true, ) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) add_node!( t, FST(PUNCTUATION, -1, n.startline, n.startline, ")"), - s, + s; join_lines = true, ) else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end end @@ -1752,7 +1752,7 @@ function p_binaryopcall( if ns > 0 add_node!(t, Whitespace(ns), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) # Add whitespace after the operator if ns > 0 if nest @@ -1777,7 +1777,7 @@ function p_binaryopcall( end end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) # Add whitespace after the operator if !is_dot && ns > 0 @@ -1806,7 +1806,7 @@ function p_binaryopcall( add_node!( t, n, - s, + s; join_lines = true, override_join_lines_based_on_source = !nest, ) @@ -1881,38 +1881,38 @@ function p_whereopcall( for (i, a) in enumerate(childs) if kind(a) === K"where" && !haschildren(a) add_node!(t, Whitespace(1), s) - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Whitespace(1), s) after_where = true elseif kind(a) === K"{" && nest - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Placeholder(0), s) s.indent += s.opts.indent elseif kind(a) === K"}" && nest add_node!(t, TrailingComma(), s) add_node!(t, Placeholder(0), s) - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) s.indent -= s.opts.indent elseif kind(a) === K"," - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) if needs_placeholder(childs, i + 1, K"}") add_node!(t, Placeholder(nws), s) end elseif JuliaSyntax.is_whitespace(a) - add_node!(t, pretty(style, a, s), s, join_lines = true) + add_node!(t, pretty(style, a, s), s; join_lines = true) else n = pretty(style, a, s, newctx(ctx; from_typedef = after_where), lineage) if after_where && add_braces brace = FST(PUNCTUATION, -1, n.endline, n.endline, "{") - add_node!(t, brace, s, join_lines = true) + add_node!(t, brace, s; join_lines = true) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if after_where && add_braces brace = FST(PUNCTUATION, -1, n.endline, n.endline, "}") - add_node!(t, brace, s, join_lines = true) + add_node!(t, brace, s; join_lines = true) end end end @@ -1934,10 +1934,10 @@ function p_conditionalopcall( for c in children(cst) if kind(c) in KSet"? :" && !haschildren(c) add_node!(t, Whitespace(1), s) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) add_node!(t, Placeholder(1), s) else - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end end @@ -1964,7 +1964,7 @@ function p_unaryopcall( if i > 1 && kind(c) in KSet"Whitespace" add_node!(t, Whitespace(1), s) end - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end t end @@ -1994,7 +1994,7 @@ function p_curly( n = pretty(style, a, s, newctx(ctx; from_typedef = true), lineage) if kind(a) === K"{" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if nest add_node!(t, Placeholder(0), s) end @@ -2003,14 +2003,14 @@ function p_curly( add_node!(t, TrailingComma(), s) add_node!(t, Placeholder(0), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K"}") add_node!(t, Placeholder(nws), s) end else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end t @@ -2098,22 +2098,22 @@ function p_invisbrackets( for c in children(cst) if kind(c) === K"(" - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(c) === K")" nest && add_node!(t, Placeholder(0), s) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) elseif kind(c) === K"block" add_node!( t, pretty(style, c, s, newctx(ctx; from_quote = true), lineage), - s, + s; join_lines = true, ) elseif is_opcall(c) - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) else - add_node!(t, pretty(style, c, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, c, s, ctx, lineage), s; join_lines = true) end end @@ -2147,7 +2147,7 @@ function p_tuple( end if kind(a) === K"(" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(a) === K")" # An odd case but this could occur if there are no keyword arguments. @@ -2160,14 +2160,14 @@ function p_tuple( end add_node!(t, Placeholder(0), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K")") add_node!(t, Placeholder(1), s) end else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end t @@ -2198,21 +2198,21 @@ function p_braces( n = pretty(style, a, s, ctx, lineage) if kind(a) === K"{" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(a) === K"}" if nest add_node!(t, TrailingComma(), s) add_node!(t, Placeholder(0), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K"}") add_node!(t, Placeholder(nws), s) end else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end t @@ -2243,20 +2243,20 @@ function p_bracescat( n = pretty(style, a, s, ctx, lineage) if kind(a) === K"{" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(a) === K"}" if nest add_node!(t, Placeholder(0), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K";" if needs_placeholder(childs, i + 1, K"}") - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) add_node!(t, Placeholder(nws), s) end else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end t @@ -2285,21 +2285,21 @@ function p_vect( n = pretty(style, a, s, ctx, lineage) if kind(a) === K"[" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(a) === K"]" if nest add_node!(t, TrailingComma(), s) add_node!(t, Placeholder(0), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K"]") add_node!(t, Placeholder(1), s) end else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end t @@ -2335,13 +2335,13 @@ function p_comprehension( for c in childs n = pretty(style, c, s, ctx, lineage) if kind(c) === K"[" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) add_node!(t, Placeholder(0), s) elseif kind(c) === K"]" add_node!(t, Placeholder(0), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end @@ -2406,12 +2406,12 @@ function p_import( for a in children(cst) if kind(a) in KSet"import export using" - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Whitespace(1), s) elseif kind(a) === K":" && haschildren(a) nodes = children(a) for n in nodes - add_node!(t, pretty(style, n, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, n, s, ctx, lineage), s; join_lines = true) if kind(n) in KSet"import export using" add_node!(t, Whitespace(1), s) elseif kind(n) in KSet", :" @@ -2419,10 +2419,10 @@ function p_import( end end elseif kind(a) in KSet", :" - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Placeholder(1), s) else - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) end end t @@ -2465,7 +2465,7 @@ function p_importpath( for a in children(cst) n = pretty(style, a, s, ctx, lineage) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end t end @@ -2485,10 +2485,10 @@ function p_as( n = pretty(style, c, s, ctx, lineage) if kind(c) === K"as" add_node!(t, Whitespace(1), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) add_node!(t, Whitespace(1), s) else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end @@ -2520,20 +2520,20 @@ function p_ref( add_node!(t, TrailingComma(), s) add_node!(t, Placeholder(0), s) end - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) elseif kind(a) === K"[" - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(a) === K"," - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) if needs_placeholder(childs, i + 1, K"]") add_node!(t, Placeholder(1), s) end elseif is_opcall(a) n = pretty(style, a, s, newctx(ctx; from_ref = true, nonest = true), lineage) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) end end t @@ -2567,15 +2567,15 @@ function p_vcat( diff_line && (t.nest_behavior = AlwaysNest) if kind(a) === K"[" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) nest && add_node!(t, Placeholder(0), s) elseif kind(a) === K"]" nest && add_node!(t, Placeholder(0), s) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif JuliaSyntax.is_whitespace(a) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K";" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else # TODO: maybe we need to do something here? # [a b c d e f] is semantically different from [a b c; d e f] @@ -2589,7 +2589,7 @@ function p_vcat( add_node!(t, Placeholder(1), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end t @@ -2627,12 +2627,12 @@ function p_hcat( if JuliaSyntax.is_whitespace(a) add_node!(t, n, s; join_lines = true) elseif i > st - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K"]") add_node!(t, Whitespace(1), s) end else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end end t @@ -2759,15 +2759,15 @@ function p_generator( add_node!(t, Whitespace(1), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) add_node!(t, Placeholder(1), s) elseif kind(a) === K"," - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K")") add_node!(t, Placeholder(1), s) end else - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) end has_for_kw && diff --git a/src/styles/sciml/nest.jl b/src/styles/sciml/nest.jl index cb8454c8..7923df9b 100644 --- a/src/styles/sciml/nest.jl +++ b/src/styles/sciml/nest.jl @@ -130,7 +130,7 @@ function _n_tuple!( end for i in optimal_placeholders - fst[i] = Newline(length = fst[i].len) + fst[i] = Newline(; length = fst[i].len) end placeholder_inds = findall(n -> n.typ === PLACEHOLDER, fst.nodes) diff --git a/src/styles/sciml/pretty.jl b/src/styles/sciml/pretty.jl index ae56a291..395d7e9b 100644 --- a/src/styles/sciml/pretty.jl +++ b/src/styles/sciml/pretty.jl @@ -166,14 +166,14 @@ function p_macrocall( override = (i == first_arg_idx) || kind(a) === K")" if JuliaSyntax.is_macro_name(a) || kind(a) === K"(" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K")") add_node!(t, Placeholder(1), s) end elseif JuliaSyntax.is_whitespace(a) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif is_macroblock if n.typ === MacroBlock && t[end].typ === WHITESPACE t[end] = Placeholder(length(t[end].val)) diff --git a/src/styles/yas/pretty.jl b/src/styles/yas/pretty.jl index 96033adc..4b2d3860 100644 --- a/src/styles/yas/pretty.jl +++ b/src/styles/yas/pretty.jl @@ -73,12 +73,12 @@ function p_import( for a in children(cst) if kind(a) in KSet"import export using" - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Whitespace(1), s) elseif kind(a) === K":" && haschildren(a) nodes = children(a) for n in nodes - add_node!(t, pretty(style, n, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, n, s, ctx, lineage), s; join_lines = true) if kind(n) in KSet"import export using :" add_node!(t, Whitespace(1), s) elseif kind(n) in KSet"," @@ -86,13 +86,13 @@ function p_import( end end elseif kind(a) === K"," - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Placeholder(1), s) elseif kind(a) === K":" - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Whitespace(1), s) else - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) end end t @@ -454,19 +454,19 @@ function p_vcat( override = i == first_arg_idx || kind(a) === K"]" if kind(a) === K"[" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"]" add_node!( t, n, - s, + s; join_lines = true, override_join_lines_based_on_source = override, ) elseif JuliaSyntax.is_whitespace(a) add_node!(t, n, s; join_lines = true) elseif kind(a) === K";" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else join_lines = i == first_arg_idx ? true : t.endline == n.startline @@ -477,7 +477,7 @@ function p_vcat( add_node!( t, n, - s, + s; join_lines = join_lines, override_join_lines_based_on_source = override, ) @@ -587,7 +587,7 @@ function p_comprehension( for c in childs n = pretty(style, c, s, ctx, lineage) if kind(c) === K"[" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) else add_node!( t, @@ -643,14 +643,14 @@ function p_macrocall( override = (i == first_arg_idx) || kind(a) === K")" if JuliaSyntax.is_macro_name(a) || kind(a) === K"(" - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif kind(a) === K"," add_node!(t, n, s; join_lines = true) if needs_placeholder(childs, i + 1, K")") add_node!(t, Placeholder(1), s) end elseif JuliaSyntax.is_whitespace(a) - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) elseif is_macroblock if n.typ === MacroBlock && t[end].typ === WHITESPACE t[end] = Placeholder(length(t[end].val)) @@ -714,11 +714,11 @@ function p_whereopcall( for (i, a) in enumerate(childs) if kind(a) === K"where" && !haschildren(a) add_node!(t, Whitespace(1), s) - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Whitespace(1), s) after_where = true elseif kind(a) === K"{" - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) s.indent += s.opts.indent elseif kind(a) === K"}" add_node!( @@ -731,17 +731,17 @@ function p_whereopcall( s.indent -= s.opts.indent elseif kind(a) === K"," if needs_placeholder(childs, i + 1, K"}") - add_node!(t, pretty(style, a, s, ctx, lineage), s, join_lines = true) + add_node!(t, pretty(style, a, s, ctx, lineage), s; join_lines = true) add_node!(t, Placeholder(nws), s) end elseif JuliaSyntax.is_whitespace(a) - add_node!(t, pretty(style, a, s), s, join_lines = true) + add_node!(t, pretty(style, a, s), s; join_lines = true) else n = pretty(style, a, s, newctx(ctx; from_typedef = after_where), lineage) if after_where && add_braces brace = FST(PUNCTUATION, -1, n.endline, n.endline, "{") - add_node!(t, brace, s, join_lines = true) + add_node!(t, brace, s; join_lines = true) end override = i == first_arg_idx @@ -755,7 +755,7 @@ function p_whereopcall( if after_where && add_braces brace = FST(PUNCTUATION, -1, n.endline, n.endline, "}") - add_node!(t, brace, s, join_lines = true) + add_node!(t, brace, s; join_lines = true) end end end @@ -801,7 +801,7 @@ function p_generator( elseif !isnothing(idx) add_node!(t, Whitespace(1), s) end - add_node!(t, n, s, join_lines = true) + add_node!(t, n, s; join_lines = true) add_node!(t, Whitespace(1), s) elseif kind(a) === K"," if needs_placeholder(childs, i + 1, K")") diff --git a/test/default_style.jl b/test/default_style.jl index 26831daf..fd0469b4 100644 --- a/test/default_style.jl +++ b/test/default_style.jl @@ -346,8 +346,8 @@ foo( args..., )""" - @test fmt(str_, m = 1) == str - @test fmt(str, m = 1) == str + @test fmt(str_; m = 1) == str + @test fmt(str; m = 1) == str end @testset ": op" begin @@ -4106,7 +4106,7 @@ some_function( d, )""" - @test fmt(str_, remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = true) == str str_ = """ var = @@ -4118,7 +4118,7 @@ some_function( c)""" str = """var = func(a, b, c)""" @test fmt(str_) == str - @test fmt(str_, remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = true) == str str_ = """ var = @@ -4130,7 +4130,7 @@ some_function( c""" str = """var = a && b && c""" @test fmt(str_) == str - @test fmt(str_, remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = true) == str str_ = """ var = @@ -4145,7 +4145,7 @@ some_function( c""" str = """var = a ? b : c""" @test fmt(str_) == str - @test fmt(str_, remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = true) == str str_ = """ var = @@ -4160,7 +4160,7 @@ some_function( c""" str = """var = a + b + c""" @test fmt(str_) == str - @test fmt(str_, remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = true) == str str_ = """ var = @@ -4175,7 +4175,7 @@ some_function( c""" str = """var = a == b == c""" @test fmt(str_) == str - @test fmt(str_, remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = true) == str end @testset "align ChainOpCall indent" begin @@ -4232,8 +4232,8 @@ some_function( body end""" - @test fmt(str_, m = 74) == str - @test fmt(str, m = 75) == str_ + @test fmt(str_; m = 74) == str + @test fmt(str; m = 75) == str_ str_ = """ if argument1 && argument2 && (argument3 || argument4 || argument5) && argument6 @@ -4248,7 +4248,7 @@ some_function( body end""" - @test fmt(str_, m = 43) == str + @test fmt(str_; m = 43) == str str = """ if argument1 && @@ -4262,7 +4262,7 @@ some_function( body end""" - @test fmt(str_, m = 42) == str + @test fmt(str_; m = 42) == str end @testset "standalone lazy expr indent" begin @@ -4740,7 +4740,7 @@ some_function( b end""" @test fmt(str_, 4, 27) == str - @test fmt(str, 4, 27, join_lines_based_on_source = true) == str + @test fmt(str, 4, 27; join_lines_based_on_source = true) == str end @testset "block automatically assume nested when join_lines_based_on_source" begin @@ -4754,7 +4754,7 @@ some_function( body end""" - @test fmt(str_, 4, 16, join_lines_based_on_source = true) == str_ - @test fmt(str_, 4, 15, join_lines_based_on_source = true) == str + @test fmt(str_, 4, 16; join_lines_based_on_source = true) == str_ + @test fmt(str_, 4, 15; join_lines_based_on_source = true) == str end end diff --git a/test/format_repo.jl b/test/format_repo.jl index 445f1c44..2a4028ce 100644 --- a/test/format_repo.jl +++ b/test/format_repo.jl @@ -9,8 +9,8 @@ format(sandbox_dir) # follow up formats should be the same - @test format(sandbox_dir, join_lines_based_on_source = true) == true - @test format(sandbox_dir, join_lines_based_on_source = true, margin = 10_000) == + @test format(sandbox_dir; join_lines_based_on_source = true) == true + @test format(sandbox_dir; join_lines_based_on_source = true, margin = 10_000) == true finally try diff --git a/test/issues.jl b/test/issues.jl index efc03c4a..a1a77b95 100644 --- a/test/issues.jl +++ b/test/issues.jl @@ -147,10 +147,10 @@ @testset "issue #150" begin str_ = "const SymReg{B,MT} = ArrayReg{B,Basic,MT} where {MT <:AbstractMatrix{Basic}}" str = "const SymReg{B,MT} = ArrayReg{B,Basic,MT} where {MT<:AbstractMatrix{Basic}}" - @test fmt(str_, whitespace_typedefs = false) == str + @test fmt(str_; whitespace_typedefs = false) == str str = "const SymReg{B, MT} = ArrayReg{B, Basic, MT} where {MT <: AbstractMatrix{Basic}}" - @test fmt(str_, whitespace_typedefs = true) == str + @test fmt(str_; whitespace_typedefs = true) == str end @testset "issue #170 - block within comprehension" begin @@ -324,8 +324,8 @@ weightedsum(Qe) end end""" - @test fmt(str_, m = 81) == str - @test fmt(str, m = 82) == str_ + @test fmt(str_; m = 81) == str + @test fmt(str; m = 82) == str_ end @testset "issue #202" begin @@ -345,7 +345,7 @@ end return function (xs) end end""" - @test fmt(str_, m = 92) == str + @test fmt(str_; m = 92) == str str_ = """ @vlplot( @@ -383,7 +383,7 @@ ], } )""" - @test fmt(str_, m = 92) == str + @test fmt(str_; m = 92) == str end @testset "issue #207" begin @@ -398,7 +398,7 @@ n::Int = 1; y_past = get_y(m), ) where {T,TGP<:AbstractGP{T};IsMultiOutput{TGP}} end""" - @test fmt(str_, m = 92) == str + @test fmt(str_; m = 92) == str str = """ @traitfn function predict_ar( @@ -407,7 +407,7 @@ n::Int = 1; y_past = get_y(m), ) where {T, TGP <: AbstractGP{T}; IsMultiOutput{TGP}} end""" - @test fmt(str_, m = 92, whitespace_typedefs = true) == str + @test fmt(str_; m = 92, whitespace_typedefs = true) == str str_ = """ @traitfn function predict_ar(m::TGP, p::Int = 3, n::Int = 1; y_past = get_y(m)) where C <: Union{T,TGP<:AbstractGP{T};IsMultiOutput{TGP}} @@ -420,7 +420,7 @@ n::Int = 1; y_past = get_y(m), ) where {C<:Union{T,TGP<:AbstractGP{T};IsMultiOutput{TGP}}} end""" - @test fmt(str_, m = 92) == str + @test fmt(str_; m = 92) == str str = """ @traitfn function predict_ar( @@ -429,7 +429,7 @@ n::Int = 1; y_past = get_y(m), ) where {C <: Union{T, TGP <: AbstractGP{T}; IsMultiOutput{TGP}}} end""" - @test fmt(str_, m = 92, whitespace_typedefs = true) == str + @test fmt(str_; m = 92, whitespace_typedefs = true) == str end @testset "issue #218" begin @@ -529,7 +529,7 @@ str_ = "get_actions(env)[env |> π.learner |> π.explorer]" str = "get_actions(env)[env|>π.learner|>π.explorer]" @test fmt(str_) == str - @test fmt(str, whitespace_ops_in_indices = true) == str_ + @test fmt(str; whitespace_ops_in_indices = true) == str_ end @testset "issue 286 - Float32 leading/trailing zeros" begin @@ -622,7 +622,7 @@ θ = eigvals(Matrix([0I(n^2) -I(n^2); P0 P1]), -Matrix([I(n^2) 0I(n^2); 0I(n^2) P2])) c = maximum(abs.(θ[(imag.(θ) .== 0) .* (real.(θ) .> 0)])) """ - @test format_text(str_, align_assignment = true) == str + @test format_text(str_; align_assignment = true) == str end @testset "issue 332" begin @@ -674,7 +674,7 @@ a = f + m + l + k end""" - @test yasfmt(str_, always_for_in = true, join_lines_based_on_source = false) == str + @test yasfmt(str_; always_for_in = true, join_lines_based_on_source = false) == str str_ = """ using Test @@ -692,7 +692,7 @@ @test true end """ - @test bluefmt(str_, always_for_in = true) == str + @test bluefmt(str_; always_for_in = true) == str end @testset "issue 387" begin @@ -701,15 +701,15 @@ new{T1, T2}(arg1, arg2)""" - @test yasfmt(str_, m = 1) == str + @test yasfmt(str_; m = 1) == str end if VERSION >= v"1.6.0" @testset "issue 396 (import as)" begin str = """import Base.threads as th""" @test fmt(str) == str - @test fmt(str, m = 1) == str - @test fmt(str, m = 1, import_to_using = true) == str + @test fmt(str; m = 1) == str + @test fmt(str; m = 1, import_to_using = true) == str end end @@ -719,7 +719,7 @@ raw\""" Doc string.\"""f end """ - @test fmt(str, always_use_return = true) == str + @test fmt(str; always_use_return = true) == str str = """ function __init__() @@ -729,7 +729,7 @@ f end """ - @test fmt(str, always_use_return = true) == str + @test fmt(str; always_use_return = true) == str str = """ function __init__() @@ -739,7 +739,7 @@ f end """ - @test fmt(str, always_use_return = true) == str + @test fmt(str; always_use_return = true) == str end @testset "issue 417" begin @@ -764,13 +764,13 @@ [z for y in x for z in y] """ @test yasfmt(str) == str - @test yasfmt(str, m = 25) == str + @test yasfmt(str; m = 25) == str str_ = """ [z for y in x for z in y] """ - @test yasfmt(str, m = 24) == str_ + @test yasfmt(str; m = 24) == str_ str_ = """ [z @@ -779,7 +779,7 @@ for z in y] """ - @test yasfmt(str, m = 1) == str_ + @test yasfmt(str; m = 1) == str_ end @testset "issue 427" begin @@ -789,7 +789,7 @@ str_ = """ var\"##iv#469\" = (@variables(t))[1]""" - @test fmt(str, m = length(str) - 1) == str_ + @test fmt(str; m = length(str) - 1) == str_ end @testset "issue 429" begin @@ -801,7 +801,7 @@ (find_derivatives!(vars, expr.lhs, f); find_derivatives!(vars, expr.rhs, f); vars) end """ - @test fmt(str, m = 92, short_to_long_function_def = true) == str_ + @test fmt(str; m = 92, short_to_long_function_def = true) == str_ end @testset "issue 440" begin @@ -824,8 +824,8 @@ body end """ - @test fmt(str_, m = 1) == str - @test bluefmt(str_, m = 1) == str + @test fmt(str_; m = 1) == str + @test bluefmt(str_; m = 1) == str end @testset "issue 431" begin @@ -869,7 +869,7 @@ end end """ - @test fmt(str_, import_to_using = true) == str + @test fmt(str_; import_to_using = true) == str end @testset "issue 456" begin @@ -880,7 +880,7 @@ var3 = 2 end """ - @test fmt(str, align_assignment = true) == str + @test fmt(str; align_assignment = true) == str str = """ function update() @@ -896,7 +896,7 @@ var3 = 5 end """ - @test fmt(str, align_assignment = true) == str_aligned + @test fmt(str; align_assignment = true) == str_aligned end @testset "issue 460" begin @@ -920,7 +920,7 @@ @everywhere import Distributed have_workers = Distributed.nprocs() - 1 """ - @test fmt(str, import_to_using = true) == str + @test fmt(str; import_to_using = true) == str end @testset "issue 463" begin @@ -934,7 +934,7 @@ end """ @test fmt( - str, + str; annotate_untyped_fields_with_any = false, align_struct_field = true, ) == str @@ -950,8 +950,8 @@ @testset "issue 473" begin str_ = "[1.0, 2.0, 3.0] .|> Int" str = "Int.([1.0, 2.0, 3.0])" - @test fmt(str_, pipe_to_function_call = true) == str - st = run_format(str_, opts = Options(pipe_to_function_call = true)) + @test fmt(str_; pipe_to_function_call = true) == str + st = run_format(str_; opts = Options(; pipe_to_function_call = true)) @test st.line_offset == length(str) end @@ -967,7 +967,7 @@ @test fmt( str, 4, - 100, + 100; whitespace_in_kwargs = false, separate_kwargs_with_semicolon = true, ) == str @@ -980,7 +980,7 @@ @test fmt( str, 4, - 100, + 100; whitespace_in_kwargs = false, separate_kwargs_with_semicolon = true, ) == str @@ -992,7 +992,7 @@ @test yasfmt( str, 4, - 100, + 100; margin = 100, whitespace_in_kwargs = false, separate_kwargs_with_semicolon = true, @@ -1005,7 +1005,7 @@ @test yasfmt( str, 4, - 100, + 100; margin = 100, whitespace_in_kwargs = false, separate_kwargs_with_semicolon = true, @@ -1194,16 +1194,16 @@ @testset "514" begin str_ = "output = input .|> f.g" str = "output = f.g.(input)" - @test fmt(str_, pipe_to_function_call = true) == str + @test fmt(str_; pipe_to_function_call = true) == str str_ = "output = input .|> f.g.h" str = "output = f.g.h.(input)" - @test fmt(str_, pipe_to_function_call = true) == str + @test fmt(str_; pipe_to_function_call = true) == str end @testset "526" begin str = "Base.:(|>)(r::AbstractRegister, blk::AbstractBlock) = apply!(r, blk)" - @test fmt(str, pipe_to_function_call = true) == str + @test fmt(str; pipe_to_function_call = true) == str end @testset "480" begin @@ -1248,23 +1248,23 @@ @testset "533" begin # semicolon should not be added prior to `extrap` since it's a function definition. s = "function linterp(x0::T, y0::T, x1::T, y1::T, x::T, extrap::Bool = false)::T where {T<:AbstractFloat} end" - @test bluefmt(s, m = 200) == s - @test yasfmt(s, m = 200) == s + @test bluefmt(s; m = 200) == s + @test yasfmt(s; m = 200) == s s = "function linterp(x0::T, y0::T, x1::T, y1::T, x::T, extrap::Bool = false)::T end" - @test bluefmt(s, m = 200) == s - @test yasfmt(s, m = 200) == s + @test bluefmt(s; m = 200) == s + @test yasfmt(s; m = 200) == s end @testset "541" begin str = """ [10;] """ - @test fmt(str, align_matrix = true) == str + @test fmt(str; align_matrix = true) == str str = """ [0:0.2:50;] """ - @test fmt(str, align_matrix = true) == str + @test fmt(str; align_matrix = true) == str end @testset "543" begin @@ -1279,7 +1279,7 @@ Zero Zero H ] """ - @test fmt(str_, align_matrix = true) == str + @test fmt(str_; align_matrix = true) == str str_ = """ H = [1 1; 1 1] @@ -1324,7 +1324,7 @@ Zero Zero H ] """ - @test fmt(str_, align_matrix = true) == str + @test fmt(str_; align_matrix = true) == str end @testset "546" begin @@ -1351,7 +1351,7 @@ @test yasfmt( str, 4, - 92, + 92; join_lines_based_on_source = true, always_use_return = true, whitespace_in_kwargs = false, @@ -1433,7 +1433,7 @@ @testset "636" begin s = "a |> M.f" - @test fmt(s, 4, 92, pipe_to_function_call = true) == "M.f(a)" + @test fmt(s, 4, 92; pipe_to_function_call = true) == "M.f(a)" # -> has a higher precedence than |> s = """ @@ -1442,7 +1442,7 @@ s_ = """ coordsperm = (x -> CartesianIndex(x.I[[2, 1, 3]])).(coords) """ - @test fmt(s, 4, 92, pipe_to_function_call = true) == s_ + @test fmt(s, 4, 92; pipe_to_function_call = true) == s_ # -> has a higher precedence than |> s = """ @@ -1451,7 +1451,7 @@ s_ = """ coordsperm = (x -> CartesianIndex.(x.I[[2, 1, 3]])).(coords) """ - @test fmt(s, 4, 92, pipe_to_function_call = true) == s_ + @test fmt(s, 4, 92; pipe_to_function_call = true) == s_ s = """ coordsperm = coords .|> (x -> x.I[[2, 1, 3]]) .|> CartesianIndex @@ -1459,7 +1459,7 @@ s_ = """ coordsperm = CartesianIndex.((x -> x.I[[2, 1, 3]]).(coords)) """ - @test fmt(s, 4, 92, pipe_to_function_call = true) == s_ + @test fmt(s, 4, 92; pipe_to_function_call = true) == s_ s = """ coordsperm = coords |> (x -> x.I[[2, 1, 3]]) |> CartesianIndex @@ -1467,7 +1467,7 @@ s_ = """ coordsperm = CartesianIndex((x -> x.I[[2, 1, 3]])(coords)) """ - @test fmt(s, 4, 92, pipe_to_function_call = true) == s_ + @test fmt(s, 4, 92; pipe_to_function_call = true) == s_ end @testset "618" begin @@ -1477,7 +1477,7 @@ s_ = """ (x -> 2x)(2) """ - @test fmt(s, 4, 92, pipe_to_function_call = true) == s_ + @test fmt(s, 4, 92; pipe_to_function_call = true) == s_ end @testset "644" begin @@ -1491,7 +1491,7 @@ @foo @noinline Base.@constprop :none bbbbbbbbbbbbbbbbbbb() = 0 @foo @foo @ccccccccccccccccccccccccccccccccccccccccccccccccc() = 0 """ - @test fmt(s, 4, 92, align_assignment = true) == s_ + @test fmt(s, 4, 92; align_assignment = true) == s_ # no manual edit s = """ @@ -1499,7 +1499,7 @@ @foo @noinline Base.@constprop :none bbbbbbbbbbbbbbbbbbbbbbb() = 0 @foo @foo @ccccccccccccccccccccccccccccccccccccccccccccccccc() = 0 """ - @test fmt(s, 4, 92, align_assignment = true) == s + @test fmt(s, 4, 92; align_assignment = true) == s end @testset "655" begin @@ -1508,16 +1508,16 @@ a; ] """ - @test fmt(s, 2, 92, join_lines_based_on_source = true) == s + @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) == + @test fmt(s, 2, 92; join_lines_based_on_source = true, trailing_comma = nothing) == s - @test fmt(s, 2, 1, trailing_comma = nothing) == s + @test fmt(s, 2, 1; trailing_comma = nothing) == s end @testset "656" begin @@ -1538,7 +1538,7 @@ \""" @dimension 𝐀 "𝐀" Angle true """ - @test fmt(s, format_docstrings = true) == s + @test fmt(s; format_docstrings = true) == s end @testset "682" begin @@ -1564,7 +1564,7 @@ 1 end """ - @test fmt(s1, 2, 5, short_to_long_function_def = true) == s2 + @test fmt(s1, 2, 5; short_to_long_function_def = true) == s2 end @testset "698" begin @@ -1596,7 +1596,7 @@ hello() end """ - @test fmt(s1, 4, 10, short_to_long_function_def = true) == s2 + @test fmt(s1, 4, 10; short_to_long_function_def = true) == s2 end @testset "700" begin @@ -1623,7 +1623,7 @@ bcd :: String end """ - @test fmt(s, 4, 92, align_struct_field = true) == s + @test fmt(s, 4, 92; align_struct_field = true) == s end end @@ -1634,7 +1634,7 @@ s2 = """ [1.0 1; 1 -1] """ - @test fmt(s1, 4, 92, align_matrix = true) == s2 + @test fmt(s1, 4, 92; align_matrix = true) == s2 end @testset "714" begin @@ -1653,7 +1653,7 @@ # empty end """ - @test fmt(s, 4, 92, always_use_return = true) == s + @test fmt(s, 4, 92; always_use_return = true) == s end @testset "728" begin s = """ @@ -1707,7 +1707,7 @@ 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 + @test fmt(str_, 4, 92; join_lines_based_on_source = true) == str end @testset "753" begin @@ -1760,7 +1760,7 @@ const a end """ - @test fmt(s, 4, 92, align_struct_field = true) == s + @test fmt(s, 4, 92; align_struct_field = true) == s end end @@ -1827,7 +1827,7 @@ ) """ @test format_text( - s1, + s1; style = BlueStyle(), trailing_comma = true, join_lines_based_on_source = true, @@ -1846,7 +1846,7 @@ ) """ @test format_text( - s1, + s1; style = BlueStyle(), trailing_comma = true, join_lines_based_on_source = true, diff --git a/test/options.jl b/test/options.jl index bdd46a6b..d9085d6d 100644 --- a/test/options.jl +++ b/test/options.jl @@ -31,8 +31,8 @@ # hello """ - @test fmt(str_, remove_extra_newlines = true) == str - @test fmt(str_, remove_extra_newlines = false) == str_ + @test fmt(str_; remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = false) == str_ str_ = """ module M @@ -66,14 +66,14 @@ end """ - @test fmt(str_, remove_extra_newlines = true) == str - @test fmt(str_, remove_extra_newlines = false) == str_ + @test fmt(str_; remove_extra_newlines = true) == str + @test fmt(str_; remove_extra_newlines = false) == str_ end @testset "whitespace in typedefs" begin str_ = "Foo{A,B,C}" str = "Foo{A, B, C}" - @test fmt(str_, whitespace_typedefs = true) == str + @test fmt(str_; whitespace_typedefs = true) == str str_ = """ struct Foo{A<:Bar,Union{B<:Fizz,C<:Buzz},<:Any} @@ -83,7 +83,7 @@ struct Foo{A <: Bar, Union{B <: Fizz, C <: Buzz}, <:Any} a::A end""" - @test fmt(str_, whitespace_typedefs = true) == str + @test fmt(str_; whitespace_typedefs = true) == str str_ = """ function foo() where {A,B,C{D,E,F{G,H,I},J,K},L,M<:N,Y>:Z} @@ -95,51 +95,51 @@ body end """ - @test fmt(str_, whitespace_typedefs = true) == str + @test fmt(str_; whitespace_typedefs = true) == str str_ = "foo() where {A,B,C{D,E,F{G,H,I},J,K},L,M<:N,Y>:Z} = body" str = "foo() where {A, B, C{D, E, F{G, H, I}, J, K}, L, M <: N, Y >: Z} = body" - @test fmt(str_, whitespace_typedefs = true) == str + @test fmt(str_; whitespace_typedefs = true) == str end @testset "whitespace ops in indices" begin str = "arr[1 + 2]" - @test fmt("arr[1+2]", m = 1, whitespace_ops_in_indices = true) == str + @test fmt("arr[1+2]"; m = 1, whitespace_ops_in_indices = true) == str str = "arr[(1 + 2)]" - @test fmt("arr[(1+2)]", m = 1, whitespace_ops_in_indices = true) == str + @test fmt("arr[(1+2)]"; m = 1, whitespace_ops_in_indices = true) == str str_ = "arr[1:2*num_source*num_dump-1]" str = "arr[1:(2 * num_source * num_dump - 1)]" - @test fmt(str_, m = 1, whitespace_ops_in_indices = true) == str + @test fmt(str_; m = 1, whitespace_ops_in_indices = true) == str str_ = "arr[2*num_source*num_dump-1:1]" str = "arr[(2 * num_source * num_dump - 1):1]" - @test fmt(str_, m = 1, whitespace_ops_in_indices = true) == str + @test fmt(str_; m = 1, whitespace_ops_in_indices = true) == str str = "arr[(a + b):c]" - @test fmt("arr[(a+b):c]", m = 1, whitespace_ops_in_indices = true) == str + @test fmt("arr[(a+b):c]"; m = 1, whitespace_ops_in_indices = true) == str str = "arr[a in b]" - @test fmt(str, m = 1, whitespace_ops_in_indices = true) == str + @test fmt(str; m = 1, whitespace_ops_in_indices = true) == str str_ = "a:b+c:d-e" str = "a:(b+c):(d-e)" - @test fmt(str_, m = 1, whitespace_ops_in_indices = true) == str + @test fmt(str_; m = 1, whitespace_ops_in_indices = true) == str str_ = "s[m+i+1]" # issue 180 str = "s[m+i+1]" - @test fmt(str, m = 1, whitespace_ops_in_indices = false) == str + @test fmt(str; m = 1, whitespace_ops_in_indices = false) == str str = "s[m + i + 1]" - @test fmt(str_, m = 1, whitespace_ops_in_indices = true) == str + @test fmt(str_; m = 1, whitespace_ops_in_indices = true) == str end @testset "rewrite import to using" begin str_ = "import A" str = "using A: A" - @test fmt(str_, import_to_using = true) == str + @test fmt(str_; import_to_using = true) == str str_ = """ import A, @@ -150,7 +150,7 @@ using B: B using C: C""" - @test fmt(str_, import_to_using = true) == str + @test fmt(str_; import_to_using = true) == str str_ = """ import A, @@ -161,7 +161,7 @@ # comment using B: B using C: C""" - @test fmt(str_, import_to_using = true) == str + @test fmt(str_; import_to_using = true) == str str_ = """ import A, # inline @@ -172,7 +172,7 @@ # comment using B: B using C: C # inline""" - @test fmt(str_, import_to_using = true) == str + @test fmt(str_; import_to_using = true) == str str_ = """ import ..A, .B, ...C""" @@ -180,25 +180,25 @@ using ..A: A using .B: B using ...C: C""" - @test fmt(str_, import_to_using = true) == str - t = run_pretty(str_, opts = Options(margin = 80, import_to_using = true)) + @test fmt(str_; import_to_using = true) == str + t = run_pretty(str_; opts = Options(; margin = 80, import_to_using = true)) @test t.len == 13 # issue 232 str = """import A.b""" - @test fmt(str, import_to_using = true) == str + @test fmt(str; import_to_using = true) == str str = """import A.b: c""" - @test fmt(str, import_to_using = true) == str + @test fmt(str; import_to_using = true) == str str = """import A.b.c""" - @test fmt(str, import_to_using = true) == str + @test fmt(str; import_to_using = true) == str str = """import A.b.c: d""" - @test fmt(str, import_to_using = true) == str + @test fmt(str; import_to_using = true) == str str = "import ..A" - @test fmt(str, import_to_using = true) == str + @test fmt(str; import_to_using = true) == str end @testset "always convert `=` to `in` (for loops)" begin @@ -210,8 +210,8 @@ for i in 1:n println(i) end""" - @test fmt(str_, always_for_in = true) == str - @test fmt(str, always_for_in = true) == str + @test fmt(str_; always_for_in = true) == str + @test fmt(str; always_for_in = true) == str str_ = """ for i = I1, j in I2 @@ -221,8 +221,8 @@ for i in I1, j in I2 println(i, j) end""" - @test fmt(str_, always_for_in = true) == str - @test fmt(str, always_for_in = true) == str + @test fmt(str_; always_for_in = true) == str + @test fmt(str; always_for_in = true) == str str_ = """ for i = 1:30, j = 100:-2:1 @@ -232,49 +232,49 @@ for i in 1:30, j in 100:-2:1 println(i, j) end""" - @test fmt(str_, always_for_in = true) == str - @test fmt(str, always_for_in = true) == str - @test fmt(str_, always_for_in = nothing) == str_ - @test fmt(str, always_for_in = nothing) == str + @test fmt(str_; always_for_in = true) == str + @test fmt(str; always_for_in = true) == str + @test fmt(str_; always_for_in = nothing) == str_ + @test fmt(str; always_for_in = nothing) == str str_ = "[(i,j) for i=I1,j=I2]" str = "[(i, j) for i in I1, j in I2]" - @test fmt(str_, always_for_in = true) == str - @test fmt(str, always_for_in = true) == str + @test fmt(str_; always_for_in = true) == str + @test fmt(str; always_for_in = true) == str str_ = "((i,j) for i=I1,j=I2)" str = "((i, j) for i in I1, j in I2)" - @test fmt(str_, always_for_in = true) == str - @test fmt(str, always_for_in = true) == str + @test fmt(str_; always_for_in = true) == str + @test fmt(str; always_for_in = true) == str str_ = "[(i, j) for i = 1:2:10, j = 100:-1:10]" str = "[(i, j) for i in 1:2:10, j in 100:-1:10]" - @test fmt(str_, always_for_in = true) == str - @test fmt(str, always_for_in = true) == str + @test fmt(str_; always_for_in = true) == str + @test fmt(str; always_for_in = true) == str str_ = "[i for i = 1:10 if i == 2]" str = "[i for i in 1:10 if i == 2]" - @test fmt(str_, always_for_in = true) == str - @test fmt(str, always_for_in = true) == str + @test fmt(str_; always_for_in = true) == str + @test fmt(str; always_for_in = true) == str str_ = "[(i, j) for i = 1:2:10, j = 100:-1:10]" str = "[(i, j) for i in 1:2:10, j in 100:-1:10]" - @test yasfmt(str_, always_for_in = true) == str - @test yasfmt(str, always_for_in = true) == str + @test yasfmt(str_; always_for_in = true) == str + @test yasfmt(str; always_for_in = true) == str str_ = "[i for i = 1:10 if i == 2]" str = "[i for i in 1:10 if i == 2]" - @test yasfmt(str_, always_for_in = true) == str - @test yasfmt(str, always_for_in = true) == str + @test yasfmt(str_; always_for_in = true) == str + @test yasfmt(str; always_for_in = true) == str end @testset "rewrite x |> f to f(x)" begin - @test fmt("x |> f", pipe_to_function_call = true) == "f(x)" + @test fmt("x |> f"; pipe_to_function_call = true) == "f(x)" str_ = "var = func1(arg1) |> func2 |> func3 |> func4 |> func5" str = "var = func5(func4(func3(func2(func1(arg1)))))" - @test fmt(str_, pipe_to_function_call = true) == str - @test fmt(str_, pipe_to_function_call = true, margin = 1) == fmt(str) + @test fmt(str_; pipe_to_function_call = true) == str + @test fmt(str_; pipe_to_function_call = true, margin = 1) == fmt(str) end @testset "function shortdef to longdef" begin @@ -283,38 +283,38 @@ function foo(a) bodybodybody end""" - @test fmt(str_, 4, length(str_), short_to_long_function_def = true) == str_ - @test fmt(str_, 4, length(str_) - 1, short_to_long_function_def = true) == str + @test fmt(str_, 4, length(str_); short_to_long_function_def = true) == str_ + @test fmt(str_, 4, length(str_) - 1; short_to_long_function_def = true) == str str_ = "foo(a::T) where {T} = bodybodybodybodybodybodyb" str = """ function foo(a::T) where {T} bodybodybodybodybodybodyb end""" - @test fmt(str_, 4, length(str_), short_to_long_function_def = true) == str_ - @test fmt(str_, 4, length(str_) - 1, short_to_long_function_def = true) == str + @test fmt(str_, 4, length(str_); short_to_long_function_def = true) == str_ + @test fmt(str_, 4, length(str_) - 1; short_to_long_function_def = true) == str str_ = "foo(a::T)::R where {T} = bodybodybodybodybodybodybody" str = """ function foo(a::T)::R where {T} bodybodybodybodybodybodybody end""" - @test fmt(str_, 4, length(str_), short_to_long_function_def = true) == str_ + @test fmt(str_, 4, length(str_); short_to_long_function_def = true) == str_ @test fmt( str_, 4, - length(str_), + length(str_); short_to_long_function_def = true, force_long_function_def = true, ) == str @test fmt( str_, 4, - length(str_), + length(str_); short_to_long_function_def = false, force_long_function_def = false, ) == str_ - @test fmt(str_, 4, length(str_) - 1, short_to_long_function_def = true) == str + @test fmt(str_, 4, length(str_) - 1; short_to_long_function_def = true) == str end @testset "function longdef to shortdef" begin @@ -323,38 +323,38 @@ bodybodybody end""" str = "foo(a) = bodybodybody" - @test fmt(str_, 4, length(str) - 1, long_to_short_function_def = true) == str_ - @test fmt(str_, 4, length(str), long_to_short_function_def = true) == str + @test fmt(str_, 4, length(str) - 1; long_to_short_function_def = true) == str_ + @test fmt(str_, 4, length(str); long_to_short_function_def = true) == str str_ = """ function foo(a::T) where {T} bodybodybodybodybodybodyb end""" str = "foo(a::T) where {T} = bodybodybodybodybodybodyb" - @test fmt(str_, 4, length(str) - 1, long_to_short_function_def = true) == str_ - @test fmt(str_, 4, length(str), long_to_short_function_def = true) == str + @test fmt(str_, 4, length(str) - 1; long_to_short_function_def = true) == str_ + @test fmt(str_, 4, length(str); long_to_short_function_def = true) == str str_ = """ function foo(a::T)::R where {T} bodybodybodybodybodybodybody end""" str = "foo(a::T)::R where {T} = bodybodybodybodybodybodybody" - @test fmt(str_, 4, length(str) - 1, long_to_short_function_def = true) == str_ - @test fmt(str_, 4, length(str), long_to_short_function_def = true) == str + @test fmt(str_, 4, length(str) - 1; long_to_short_function_def = true) == str_ + @test fmt(str_, 4, length(str); long_to_short_function_def = true) == str str_ = """ function foo(a) return a + 1 end""" str = "foo(a) = a + 1" - @test fmt(str_, 4, length(str), long_to_short_function_def = true) == str + @test fmt(str_, 4, length(str); long_to_short_function_def = true) == str str = """ function foo() expr1 expr2 end""" - @test fmt(str, 4, length(str), long_to_short_function_def = true) == str + @test fmt(str, 4, length(str); long_to_short_function_def = true) == str str_ = """ function foo(a) @@ -372,8 +372,8 @@ else nothing end""" - @test fmt1(str_, 4, length(str), long_to_short_function_def = true) == str - @test fmt(str_, 4, length(str), long_to_short_function_def = true) == str + @test fmt1(str_, 4, length(str); long_to_short_function_def = true) == str + @test fmt(str_, 4, length(str); long_to_short_function_def = true) == str end @testset "always use return" begin @@ -385,7 +385,7 @@ @test fmt( str_, 4, - length(str_) - 1, + length(str_) - 1; short_to_long_function_def = true, always_use_return = true, ) == str @@ -400,7 +400,7 @@ expr1 return expr2 end""" - @test fmt(str_, 4, length(str_) - 1, always_use_return = true) == str + @test fmt(str_, 4, length(str_) - 1; always_use_return = true) == str str_ = """ macro foo() @@ -412,7 +412,7 @@ expr1 return expr2 end""" - @test fmt(str_, 4, length(str_) - 1, always_use_return = true) == str + @test fmt(str_, 4, length(str_) - 1; always_use_return = true) == str str_ = """ map(arg1, arg2) do x, y @@ -424,19 +424,19 @@ expr1 return expr2 end""" - @test fmt(str_, 4, length(str_) - 1, always_use_return = true) == str + @test fmt(str_, 4, length(str_) - 1; always_use_return = true) == str str = """ function foo() @macrocall(expr2) end""" - @test fmt(str, 4, 92, always_use_return = true) == str + @test fmt(str, 4, 92; always_use_return = true) == str str = """ function foo() @macroblock expr2 end""" - @test fmt(str, 4, 92, always_use_return = true) == str + @test fmt(str, 4, 92; always_use_return = true) == str str = """ function foo() @@ -444,7 +444,7 @@ println(i) end end""" - @test fmt(str, 4, 92, always_use_return = true) == str + @test fmt(str, 4, 92; always_use_return = true) == str str = """ function f(a) @@ -454,7 +454,7 @@ return 1 end end""" - @test fmt(str, 4, 92, always_use_return = true) == str + @test fmt(str, 4, 92; always_use_return = true) == str @testset "426" begin # throw function heuristic @@ -465,7 +465,7 @@ throw(ArgumentError("x must be 1 or 2")) end """ - @test fmt(str, always_use_return = true) == str + @test fmt(str; always_use_return = true) == str end @testset "507" begin @@ -475,39 +475,39 @@ (1 + 1; return 2) end """ - @test fmt(str, always_use_return = true) == str + @test fmt(str; always_use_return = true) == str end end @testset "whitespace in keyword arguments" begin str_ = "f(; a = b)" str = "f(; a=b)" - @test fmt(str_, 4, 92, whitespace_in_kwargs = false) == str + @test fmt(str_, 4, 92; whitespace_in_kwargs = false) == str str = "f(; a!) = a!" - @test fmt(str, 4, 92, whitespace_in_kwargs = false) == str + @test fmt(str, 4, 92; whitespace_in_kwargs = false) == str # issue 242 str_ = "f(a, b! = 1; c! = 2, d = 3, e! = 4)" str = "f(a, (b!)=1; (c!)=2, d=3, (e!)=4)" - @test fmt(str_, 4, 92, whitespace_in_kwargs = false) == str + @test fmt(str_, 4, 92; whitespace_in_kwargs = false) == str str_ = "( k1 =v1, k2! = v2)" str = "(k1=v1, (k2!)=v2)" - @test fmt(str_, 4, 80, style = YASStyle(), whitespace_in_kwargs = false) == str - @test fmt(str_, 4, 80, style = DefaultStyle(), whitespace_in_kwargs = false) == str + @test fmt(str_, 4, 80; style = YASStyle(), whitespace_in_kwargs = false) == str + @test fmt(str_, 4, 80; style = DefaultStyle(), whitespace_in_kwargs = false) == str str_ = "( k1 =v1, k2! = v2)" str = "(k1 = v1, k2! = v2)" - @test fmt(str_, 4, 80, style = YASStyle(), whitespace_in_kwargs = true) == str - @test fmt(str_, 4, 80, style = DefaultStyle(), whitespace_in_kwargs = true) == str + @test fmt(str_, 4, 80; style = YASStyle(), whitespace_in_kwargs = true) == str + @test fmt(str_, 4, 80; style = DefaultStyle(), whitespace_in_kwargs = true) == str str_ = "(; g = >=(1))" str = "(; g=(>=(1)))" - @test fmt(str_, 4, 92, whitespace_in_kwargs = false) == str + @test fmt(str_, 4, 92; whitespace_in_kwargs = false) == str s = "C(; Vt=Ȳ')" - @test fmt(s, 4, 100, whitespace_in_kwargs = false) == s + @test fmt(s, 4, 100; whitespace_in_kwargs = false) == s end @testset "annotate untyped fields with `Any`" begin @@ -572,23 +572,23 @@ struct name arg end""" - @test fmt(str_, annotate_untyped_fields_with_any = false) == str + @test fmt(str_; annotate_untyped_fields_with_any = false) == str str_ = """ struct name arg end""" - @test fmt(str_, annotate_untyped_fields_with_any = false) == str + @test fmt(str_; annotate_untyped_fields_with_any = false) == str str_ = """ struct name arg end""" - @test fmt(str_, annotate_untyped_fields_with_any = false) == str + @test fmt(str_; annotate_untyped_fields_with_any = false) == str t = run_pretty( - str_, - opts = Options(margin = 80, annotate_untyped_fields_with_any = false), + str_; + opts = Options(; margin = 80, annotate_untyped_fields_with_any = false), ) @test length(t) == 11 @@ -601,23 +601,23 @@ mutable struct name reallylongfieldname end""" - @test fmt(str_, annotate_untyped_fields_with_any = false) == str + @test fmt(str_; annotate_untyped_fields_with_any = false) == str str_ = """ mutable struct name reallylongfieldname end""" - @test fmt(str_, annotate_untyped_fields_with_any = false) == str + @test fmt(str_; annotate_untyped_fields_with_any = false) == str str_ = """ mutable struct name reallylongfieldname end""" - @test fmt(str_, annotate_untyped_fields_with_any = false) == str + @test fmt(str_; annotate_untyped_fields_with_any = false) == str t = run_pretty( - str_, - opts = Options(margin = 80, annotate_untyped_fields_with_any = false), + str_; + opts = Options(; margin = 80, annotate_untyped_fields_with_any = false), ) @test length(t) == 23 end @@ -649,7 +649,7 @@ 20 end""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == normalized + @test fmt(str; format_docstrings = true) == normalized str = """ \""" @@ -658,7 +658,7 @@ 20 end""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == normalized + @test fmt(str; format_docstrings = true) == normalized str = """ \"""doc\""" @@ -666,7 +666,7 @@ 20 end""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == normalized + @test fmt(str; format_docstrings = true) == normalized str = """ "doc @@ -675,7 +675,7 @@ 20 end""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == normalized + @test fmt(str; format_docstrings = true) == normalized str = """ " @@ -684,7 +684,7 @@ 20 end""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == normalized + @test fmt(str; format_docstrings = true) == normalized str = """ "doc" @@ -692,7 +692,7 @@ 20 end""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == normalized + @test fmt(str; format_docstrings = true) == normalized # test aligning to function identation str_ = """ @@ -706,7 +706,7 @@ 20 end""" @test fmt(str_) == str - @test fmt(str_, format_docstrings = true) == normalized + @test fmt(str_; format_docstrings = true) == normalized str = """\""" doc for Foo @@ -724,7 +724,7 @@ 20 end""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str # Issue 157 str = raw""" @@ -733,7 +733,7 @@ \""" foo() = bar()""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str str = raw""" @doc docϵ\""" @@ -741,23 +741,23 @@ \""" foo() = bar()""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str str = raw"""@doc "doc for foo" foo""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str str = raw"""@doc \"""doc for foo\""" foo""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str str = raw"""@doc doc\"""doc for foo\""" foo()""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str str = raw"""@doc foo""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str # issue 160 str = raw""" @@ -772,7 +772,7 @@ end # module""" @test fmt(str) == str - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str end @testset "with code" begin @@ -852,7 +852,7 @@ function test(x) x end""" - @test fmt(unformatted, format_docstrings = true) == formatted + @test fmt(unformatted; format_docstrings = true) == formatted end @testset "issue 602" begin @@ -867,7 +867,7 @@ \""" foo() = nothing """ - @test fmt(s, format_docstrings = true) == s + @test fmt(s; format_docstrings = true) == s end @testset "Multi-line indented code-blocks" begin @@ -884,7 +884,7 @@ ) \""" function fmt() end""" - @test fmt(unformatted, format_docstrings = true) == formatted + @test fmt(unformatted; format_docstrings = true) == formatted end @testset "Empty line in docstring" begin @@ -898,8 +898,8 @@ \""" \""" function test() end""" - @test fmt(unformatted, format_docstrings = true) == formatted - @test fmt(unformatted, format_docstrings = false) == unformatted + @test fmt(unformatted; format_docstrings = true) == formatted + @test fmt(unformatted; format_docstrings = false) == unformatted end @testset "Indented docstring" begin @@ -921,7 +921,7 @@ \""" indented_item end""" - @test fmt(unformatted, format_docstrings = true) == formatted + @test fmt(unformatted; format_docstrings = true) == formatted short = """ begin @@ -937,7 +937,7 @@ item end """ - @test fmt(short, format_docstrings = true) == short_formatted + @test fmt(short; format_docstrings = true) == short_formatted end @testset "issue 597" begin @@ -960,7 +960,7 @@ \""" foo() = println("hello world") """ - @test fmt(str_, format_docstrings = true) == str + @test fmt(str_; format_docstrings = true) == str s = """ \"\"\" @@ -975,7 +975,7 @@ \"\"\" foo() = [1] """ - @test fmt(str, format_docstrings = true) == str + @test fmt(str; format_docstrings = true) == str end end @@ -988,7 +988,7 @@ struct Foo a::T end""" - @test fmt(str_, align_struct_field = true) == str + @test fmt(str_; align_struct_field = true) == str str = """ struct Foo @@ -1000,8 +1000,8 @@ a :: T longfieldname :: B end""" - @test fmt(str, align_struct_field = true) == str - @test fmt(str, align_struct_field = false) == str_ + @test fmt(str; align_struct_field = true) == str + @test fmt(str; align_struct_field = false) == str_ str_ = """ Base.@kwdef struct Options @@ -1047,7 +1047,7 @@ Options() = new() end""" - @test fmt(str_, align_struct_field = true) == str + @test fmt(str_; align_struct_field = true) == str str_ = """ Base.@kwdef struct Options @@ -1071,8 +1071,8 @@ Options() = new() end""" - @test fmt(str, align_struct_field = true) == str - @test fmt(str, align_struct_field = false) == str_ + @test fmt(str; align_struct_field = true) == str + @test fmt(str; align_struct_field = false) == str_ str = """ Base.@kwdef struct Options @@ -1099,7 +1099,7 @@ Options() = new() end""" - @test fmt(str, 4, 1, align_struct_field = true) == str + @test fmt(str, 4, 1; align_struct_field = true) == str end @testset "align assignment" begin @@ -1113,14 +1113,14 @@ const var2 = 2 const var3 = 3 const var4 = 4""" - @test fmt(str_, align_assignment = true) == str + @test fmt(str_; align_assignment = true) == str str = """ const variable1 = 1 const variable2 = 2 const var3 = 3 const var4 = 4""" - @test fmt(str, align_assignment = true) == str + @test fmt(str; align_assignment = true) == str str_ = """ module Foo @@ -1167,8 +1167,8 @@ const FOO = 1 end""" - @test fmt(str_, align_assignment = true) == str - @test fmt(str_, align_assignment = true, join_lines_based_on_source = true) == str + @test fmt(str_; align_assignment = true) == str + @test fmt(str_; align_assignment = true, join_lines_based_on_source = true) == str # the aligned consts will NOT be nestable str = """ @@ -1195,8 +1195,8 @@ 1 end""" - @test fmt(str_, 4, 1, align_assignment = true) == str - @test fmt(str_, 4, 1, align_assignment = true, join_lines_based_on_source = true) == + @test fmt(str_, 4, 1; align_assignment = true) == str + @test fmt(str_, 4, 1; align_assignment = true, join_lines_based_on_source = true) == str str = """ @@ -1206,7 +1206,7 @@ long_variable = 1 other_var = 2 """ - @test fmt(str, 4, 1, align_assignment = true) == str + @test fmt(str, 4, 1; align_assignment = true) == str str = """ vcat(X::T...) where {T} = T[X[i] for i = 1:length(X)] @@ -1214,8 +1214,8 @@ hcat(X::T...) where {T} = T[X[j] for i = 1:1, j = 1:length(X)] hcat(X::T...) where {T<:Number} = T[X[j] for i = 1:1, j = 1:length(X)] """ - @test fmt(str, 4, 1, align_assignment = true) == str - @test fmt(str, 4, 1, align_assignment = true, join_lines_based_on_source = true) == + @test fmt(str, 4, 1; align_assignment = true) == str + @test fmt(str, 4, 1; align_assignment = true, join_lines_based_on_source = true) == str # ambiguous ordering @@ -1224,7 +1224,7 @@ ms, μs = divrem(μs, 1000) s, ms = divrem(ms, 1000) """ - @test fmt(str, align_assignment = true) == str + @test fmt(str; align_assignment = true) == str str = """ run = wandb.init( @@ -1243,11 +1243,11 @@ anonymous = anonymous ? "allow" : "never", ) """ - @test fmt(str, 4, 100, align_assignment = true, whitespace_in_kwargs = false) == str + @test fmt(str, 4, 100; align_assignment = true, whitespace_in_kwargs = false) == str @test fmt( str, 4, - 100, + 100; align_assignment = true, whitespace_in_kwargs = false, join_lines_based_on_source = true, @@ -1265,11 +1265,11 @@ C = s.C poles = eigvals(A - K * C) """ - @test fmt(str_, 4, 100, align_assignment = true) == str + @test fmt(str_, 4, 100; align_assignment = true) == str @test fmt( str_, 4, - 100, + 100; align_assignment = true, join_lines_based_on_source = true, ) == str @@ -1286,7 +1286,7 @@ C = s.C const polesss = eigvals(A - K * C) """ - @test fmt(str_, 4, 100, align_assignment = true) == str + @test fmt(str_, 4, 100; align_assignment = true) == str str = """ function stabilize(model) @@ -1305,11 +1305,11 @@ model end """ - @test fmt(str, 4, 100, align_assignment = true) == str + @test fmt(str, 4, 100; align_assignment = true) == str @test fmt( str, 4, - 100, + 100; align_assignment = true, join_lines_based_on_source = true, ) == str @@ -1330,7 +1330,7 @@ n, ) """ - @test fmt(str_, align_conditional = true) == str + @test fmt(str_; align_conditional = true) == str str = """ index = @@ -1341,7 +1341,7 @@ n, ) """ - @test fmt(str_, 4, 1, align_conditional = true) == str + @test fmt(str_, 4, 1; align_conditional = true) == str str_ = """ index = zeros(n <= typemax(Int8) ? Int8 : # inline @@ -1363,11 +1363,11 @@ n, ) """ - @test fmt(str_, 4, 1, align_conditional = true) == str + @test fmt(str_, 4, 1; align_conditional = true) == str @test fmt( str_, 4, - 1, + 1; align_conditional = true, join_lines_based_on_source = true, ) == str @@ -1385,11 +1385,11 @@ n, ) """ - @test fmt(str_, 4, 1, align_conditional = true) == str + @test fmt(str_, 4, 1; align_conditional = true) == str @test fmt( str_, 4, - 1, + 1; align_conditional = true, join_lines_based_on_source = true, ) == str @@ -1412,7 +1412,7 @@ n, ) """ - @test fmt(str_, 4, 1, align_conditional = true) == str + @test fmt(str_, 4, 1; align_conditional = true) == str str_ = """ val = cst.kind === Tokens.ABSTRACT ? "abstract" : @@ -1421,7 +1421,7 @@ str = """ val = cst.kind === Tokens.ABSTRACT ? "abstract" : cst.kind === Tokens.BAREMODULE ? "baremodule" : "" """ - @test fmt(str_, 4, 100, align_conditional = true) == str + @test fmt(str_, 4, 100; align_conditional = true) == str str_ = """ val = cst.kind === Tokens.ABSTRACT ? "abstract" : @@ -1431,11 +1431,11 @@ val = cst.kind === Tokens.ABSTRACT ? "abstract" : cst.kind === Tokens.BAREMODUL ? "baremodule" : "" """ - @test fmt(str_, 4, 100, align_conditional = true) == str + @test fmt(str_, 4, 100; align_conditional = true) == str @test fmt( str_, 4, - 100, + 100; align_conditional = true, join_lines_based_on_source = true, ) == str @@ -1445,11 +1445,11 @@ cst.kind === Tokens.ABSTRACT ? "abstract" : cst.kind === Tokens.BAREMODUL ? "baremodule" : "" """ - @test fmt(str_, 4, 1, align_conditional = true) == str + @test fmt(str_, 4, 1; align_conditional = true) == str @test fmt( str_, 4, - 1, + 1; align_conditional = true, join_lines_based_on_source = true, ) == str @@ -1484,7 +1484,7 @@ "API Reference" => "api.md", ] """ - @test fmt(str_, 4, 100, align_pair_arrow = true) == str + @test fmt(str_, 4, 100; align_pair_arrow = true) == str str = """ pages = @@ -1501,8 +1501,8 @@ "API Reference" => "api.md", ] """ - @test fmt(str_, 4, 1, align_pair_arrow = true) == str - @test fmt(str_, 4, 1, align_pair_arrow = true, join_lines_based_on_source = true) == + @test fmt(str_, 4, 1; align_pair_arrow = true) == str + @test fmt(str_, 4, 1; align_pair_arrow = true, join_lines_based_on_source = true) == str end @@ -1510,7 +1510,7 @@ str_ = """ E ? A : B """ - @test fmt(str_, 2, 9, conditional_to_if = true) == str_ + @test fmt(str_, 2, 9; conditional_to_if = true) == str_ str = """ if E @@ -1519,14 +1519,14 @@ B end """ - @test fmt(str_, 2, 8, conditional_to_if = true) == str + @test fmt(str_, 2, 8; conditional_to_if = true) == str str_ = """ begin E1 ? A : E2 ? B : foo(E333, E444) ? D : E end """ - @test fmt(str_, 4, 45, conditional_to_if = true) == str_ + @test fmt(str_, 4, 45; conditional_to_if = true) == str_ str = """ begin @@ -1541,8 +1541,8 @@ end end """ - @test fmt(str_, 4, 44, conditional_to_if = true) == str - @test fmt(str_, 4, 26, conditional_to_if = true) == str + @test fmt(str_, 4, 44; conditional_to_if = true) == str + @test fmt(str_, 4, 26; conditional_to_if = true) == str str = """ begin @@ -1560,7 +1560,7 @@ end end """ - @test fmt(str_, 4, 25, conditional_to_if = true) == str + @test fmt(str_, 4, 25; conditional_to_if = true) == str str_ = """ foobar = some_big_long_thing * 10_000 == 2 ? @@ -1579,7 +1579,7 @@ another_big_long_thing * 10^300 / this_things_here end """ - @test fmt(str_, conditional_to_if = true) == str + @test fmt(str_; conditional_to_if = true) == str end @testset "normalize_line_endings" begin @@ -1588,20 +1588,20 @@ mixed_windows_str = "a\r\nb\r\nc\nd" mixed_unix_str = "a\r\nb\nc\nd" - @test fmt(windows_str, normalize_line_endings = "auto") == windows_str - @test fmt(unix_str, normalize_line_endings = "auto") == unix_str - @test fmt(mixed_windows_str, normalize_line_endings = "auto") == windows_str - @test fmt(mixed_unix_str, normalize_line_endings = "auto") == unix_str + @test fmt(windows_str; normalize_line_endings = "auto") == windows_str + @test fmt(unix_str; normalize_line_endings = "auto") == unix_str + @test fmt(mixed_windows_str; normalize_line_endings = "auto") == windows_str + @test fmt(mixed_unix_str; normalize_line_endings = "auto") == unix_str - @test fmt(windows_str, normalize_line_endings = "unix") == unix_str - @test fmt(unix_str, normalize_line_endings = "unix") == unix_str - @test fmt(mixed_windows_str, normalize_line_endings = "unix") == unix_str - @test fmt(mixed_unix_str, normalize_line_endings = "unix") == unix_str + @test fmt(windows_str; normalize_line_endings = "unix") == unix_str + @test fmt(unix_str; normalize_line_endings = "unix") == unix_str + @test fmt(mixed_windows_str; normalize_line_endings = "unix") == unix_str + @test fmt(mixed_unix_str; normalize_line_endings = "unix") == unix_str - @test fmt(windows_str, normalize_line_endings = "windows") == windows_str - @test fmt(unix_str, normalize_line_endings = "windows") == windows_str - @test fmt(mixed_windows_str, normalize_line_endings = "windows") == windows_str - @test fmt(mixed_unix_str, normalize_line_endings = "windows") == windows_str + @test fmt(windows_str; normalize_line_endings = "windows") == windows_str + @test fmt(unix_str; normalize_line_endings = "windows") == windows_str + @test fmt(mixed_windows_str; normalize_line_endings = "windows") == windows_str + @test fmt(mixed_unix_str; normalize_line_endings = "windows") == windows_str end @testset "align matrix" begin @@ -1613,13 +1613,13 @@ 2 α b ] """ - @test fmt(fmt(str), align_matrix = true) == str + @test fmt(fmt(str); align_matrix = true) == str str_ = """ a = [100 300 400 1 eee 40000 2 α b] """ - @test fmt(fmt(str), align_matrix = true, style = YASStyle()) == str_ + @test fmt(fmt(str); align_matrix = true, style = YASStyle()) == str_ # left-aligned str = """ @@ -1629,13 +1629,13 @@ 2 α b ] """ - @test fmt(str, align_matrix = true) == str + @test fmt(str; align_matrix = true) == str str_ = """ a = [100 300 400 1 eee 40000 2 α b] """ - @test fmt(str, align_matrix = true, style = YASStyle()) == str_ + @test fmt(str; align_matrix = true, style = YASStyle()) == str_ # right-aligned str = """ @@ -1645,13 +1645,13 @@ 2 α 40000 ] """ - fmt(str, align_matrix = true) == str + fmt(str; align_matrix = true) == str str_ = """ a = [100 3000 400 1 eee b 2 α 40000] """ - @test fmt(str, align_matrix = true, style = YASStyle()) == str_ + @test fmt(str; align_matrix = true, style = YASStyle()) == str_ end @testset "trailing commas" begin @@ -1663,15 +1663,15 @@ )""" str_ = "funccall(arg1, arg2, arg3)" - @test fmt(str_, 4, 1, trailing_comma = false) == str + @test fmt(str_, 4, 1; trailing_comma = false) == str # last comma is removed str_ = "funccall(arg1, arg2, arg3,)" - @test fmt(str_, 4, 1, trailing_comma = false) == str + @test fmt(str_, 4, 1; trailing_comma = false) == str str = "funccall(arg1, arg2, arg3)" - @test fmt(str_, trailing_comma = false) == str + @test fmt(str_; trailing_comma = false) == str # corner case - if the comma is removed it is no longer a tuple str_ = "(tuple,)" @@ -1679,7 +1679,7 @@ ( tuple, )""" - @test fmt(str_, 4, 1, trailing_comma = false) == str + @test fmt(str_, 4, 1; trailing_comma = false) == str str = """ funccall( @@ -1689,7 +1689,7 @@ )""" str_ = "funccall(arg1, arg2, arg3)" - @test fmt(str_, 4, 1, trailing_comma = nothing) == str + @test fmt(str_, 4, 1; trailing_comma = nothing) == str # last comma is stays str_ = "funccall(arg1, arg2, arg3,)" @@ -1699,8 +1699,8 @@ arg2, arg3, )""" - @test fmt(str_, 4, 1, trailing_comma = nothing) == str - @test fmt(str_, 4, 100, trailing_comma = nothing) == str_ + @test fmt(str_, 4, 1; trailing_comma = nothing) == str + @test fmt(str_, 4, 100; trailing_comma = nothing) == str_ # corner case - if the comma is removed it is no longer a tuple str_ = "(tuple,)" @@ -1708,36 +1708,36 @@ ( tuple, )""" - @test fmt(str_, 4, 1, trailing_comma = nothing) == str + @test fmt(str_, 4, 1; trailing_comma = nothing) == str end @testset "ignore maximum width" begin @testset "maintain original structure" begin for m in (:module, :baremodule) str_ = "$m M body end" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) end str_ = "struct S body end" @test fmt( - str_, + str_; join_lines_based_on_source = true, annotate_untyped_fields_with_any = false, - ) == fmt(str_, annotate_untyped_fields_with_any = false) + ) == fmt(str_; annotate_untyped_fields_with_any = false) str_ = "mutable struct S body end" @test fmt( - str_, + str_; join_lines_based_on_source = true, annotate_untyped_fields_with_any = false, - ) == fmt(str_, annotate_untyped_fields_with_any = false) + ) == fmt(str_; annotate_untyped_fields_with_any = false) str_ = """ abstract type foo end""" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) str_ = """ primitive type @@ -1746,30 +1746,30 @@ 64 end""" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) str_ = """ function foo end""" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) for f in (:function, :macro) str_ = "$f foo() body end" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) end str_ = "try a catch e finally c end" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) str_ = "if a body1 elseif b body2 elseif c body3 else body4 end" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) str_ = "begin a;b;c end" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) str_ = "function foo() a;b;c end" - @test fmt(str_, join_lines_based_on_source = true) == fmt(str_) + @test fmt(str_; join_lines_based_on_source = true) == fmt(str_) end @testset "misc" begin @@ -1778,7 +1778,7 @@ body end """ - @test fmt(str, 4, 84, join_lines_based_on_source = true) == str + @test fmt(str, 4, 84; join_lines_based_on_source = true) == str str_ = """ function foo( @@ -1796,8 +1796,8 @@ body end """ - @test fmt(str_, join_lines_based_on_source = true) == str - @test bluefmt(str_, join_lines_based_on_source = true) == str + @test fmt(str_; join_lines_based_on_source = true) == str + @test bluefmt(str_; join_lines_based_on_source = true) == str end @testset "binary op" begin @@ -1809,13 +1809,13 @@ a = b """ - @test fmt(str_, join_lines_based_on_source = true) == str - @test bluefmt(str_, join_lines_based_on_source = true) == str + @test fmt(str_; join_lines_based_on_source = true) == str + @test bluefmt(str_; join_lines_based_on_source = true) == str str = """ a = b """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ a = @@ -1825,13 +1825,13 @@ a = (b, c) """ - @test fmt(str_, join_lines_based_on_source = true) == str + @test fmt(str_; join_lines_based_on_source = true) == str str = """ a = (b, c) """ - @test yasfmt(str_, join_lines_based_on_source = true) == str - @test bluefmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str + @test bluefmt(str_; join_lines_based_on_source = true) == str str_ = """ a = @@ -1840,9 +1840,9 @@ str = """ a = "hello" """ - @test fmt(str_, join_lines_based_on_source = true) == str - @test bluefmt(str_, join_lines_based_on_source = true) == str - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test fmt(str_; join_lines_based_on_source = true) == str + @test bluefmt(str_; join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str end @testset "blue style" begin @@ -1853,8 +1853,8 @@ body end """ - @test bluefmt(str, 4, 1000, join_lines_based_on_source = true) == str - @test bluefmt(str, 4, 1, join_lines_based_on_source = true) == + @test bluefmt(str, 4, 1000; join_lines_based_on_source = true) == str + @test bluefmt(str, 4, 1; join_lines_based_on_source = true) == bluefmt(str, 4, 1) str = """ @@ -1865,7 +1865,7 @@ body end """ - @test bluefmt(str, 4, 1000, join_lines_based_on_source = true) == str + @test bluefmt(str, 4, 1000; join_lines_based_on_source = true) == str end @testset "yas style" begin @@ -1880,8 +1880,8 @@ body end """ - @test yasfmt(str_, join_lines_based_on_source = true) == - yasfmt(str_, 4, 1, join_lines_based_on_source = false) + @test yasfmt(str_; join_lines_based_on_source = true) == + yasfmt(str_, 4, 1; join_lines_based_on_source = false) str_ = """ @foo( @@ -1893,7 +1893,7 @@ @foo(arg1, arg2,) """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ ( @@ -1905,7 +1905,7 @@ (arg1, arg2) """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ [ @@ -1917,7 +1917,7 @@ [arg1, arg2] """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ A[ @@ -1929,7 +1929,7 @@ A[arg1, arg2] """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ { @@ -1941,7 +1941,7 @@ {arg1, arg2} """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ A{ @@ -1953,7 +1953,7 @@ A{arg1, arg2} """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ ( @@ -1963,7 +1963,7 @@ str = """ (invisbrackets) """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ [ @@ -1975,7 +1975,7 @@ [row1; row2;] """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ T[ @@ -1987,7 +1987,7 @@ T[row1; row2;] """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str str_ = """ [ @@ -1997,7 +1997,7 @@ str = """ [a for a = 1:10] """ - @test yasfmt(str_, join_lines_based_on_source = true) == str + @test yasfmt(str_; join_lines_based_on_source = true) == str end @testset "imports" begin @@ -2009,7 +2009,7 @@ using A, #inline # comment B, C#inline""" - @test fmt(str_, 2, 80, join_lines_based_on_source = true) == str + @test fmt(str_, 2, 80; join_lines_based_on_source = true) == str str_ = """ using CommonMark: @@ -2030,8 +2030,8 @@ Parser, Rule, TableRule """ - @test fmt(str_, 4, 37, join_lines_based_on_source = true) == str_ - @test fmt(str_, 4, 36, join_lines_based_on_source = true) == str + @test fmt(str_, 4, 37; join_lines_based_on_source = true) == str_ + @test fmt(str_, 4, 36; join_lines_based_on_source = true) == str str = """ using CommonMark: @@ -2042,7 +2042,7 @@ Parser, Rule, TableRule """ - @test yasfmt(str_, 4, 51, join_lines_based_on_source = true) == str + @test yasfmt(str_, 4, 51; join_lines_based_on_source = true) == str str = """ using CommonMark: @@ -2054,7 +2054,7 @@ Parser, Rule, TableRule """ - @test yasfmt(str_, 4, 50, join_lines_based_on_source = true) == str + @test yasfmt(str_, 4, 50; join_lines_based_on_source = true) == str end # NOTE: not sure since test makes sense anymore. @@ -2068,7 +2068,7 @@ str = """ T[a b Expr(); d e Expr();]""" - @test fmt(str_, join_lines_based_on_source = true) == str + @test fmt(str_; join_lines_based_on_source = true) == str end @testset "function defs" begin @@ -2076,13 +2076,13 @@ function foo() end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s s = """ function foo end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s end @testset "macro defs" begin @@ -2090,13 +2090,13 @@ macro foo() end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s s = """ macro foo end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s end @testset "typedefs" begin @@ -2104,13 +2104,13 @@ struct S end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s s = """ mutable struct S end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s end @testset "modules" begin @@ -2118,13 +2118,13 @@ module M end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s s = """ baremodule BM end """ - @test fmt(s, join_lines_based_on_source = true) == s + @test fmt(s; join_lines_based_on_source = true) == s end end @@ -2169,7 +2169,7 @@ end """ - @test fmt(str_, 2, 22, indent_submodule = true) == str + @test fmt(str_, 2, 22; indent_submodule = true) == str str = """ "doc" @@ -2192,7 +2192,7 @@ end """ - @test fmt(str_, 2, 21, indent_submodule = true) == str + @test fmt(str_, 2, 21; indent_submodule = true) == str end @testset "`separate_kwargs_with_semicolon`" begin @@ -2202,28 +2202,28 @@ str = """ f(a; b = 10) """ - @test fmt(str_, separate_kwargs_with_semicolon = true) == str - @test yasfmt(str_, separate_kwargs_with_semicolon = true) == str + @test fmt(str_; separate_kwargs_with_semicolon = true) == str + @test yasfmt(str_; separate_kwargs_with_semicolon = true) == str str_ = "xy = f(x, y=3)" str = "xy = f(x; y = 3)" - @test fmt(str_, separate_kwargs_with_semicolon = true) == str - @test yasfmt(str_, separate_kwargs_with_semicolon = true) == str + @test fmt(str_; separate_kwargs_with_semicolon = true) == str + @test yasfmt(str_; separate_kwargs_with_semicolon = true) == str str_ = "xy = f(x=1, y=2)" str = "xy = f(; x = 1, y = 2)" - @test fmt1(str_, separate_kwargs_with_semicolon = true) == str - @test fmt(str_, separate_kwargs_with_semicolon = true) == str - @test fmt(str, separate_kwargs_with_semicolon = true) == str - @test yasfmt1(str_, separate_kwargs_with_semicolon = true) == str - @test yasfmt(str_, separate_kwargs_with_semicolon = true) == str - @test yasfmt(str, separate_kwargs_with_semicolon = true) == str + @test fmt1(str_; separate_kwargs_with_semicolon = true) == str + @test fmt(str_; separate_kwargs_with_semicolon = true) == str + @test fmt(str; separate_kwargs_with_semicolon = true) == str + @test yasfmt1(str_; separate_kwargs_with_semicolon = true) == str + @test yasfmt(str_; separate_kwargs_with_semicolon = true) == str + @test yasfmt(str; separate_kwargs_with_semicolon = true) == str str_ = "xy = f(x = 1; y = 2)" - @test fmt1(str_, separate_kwargs_with_semicolon = true) == str - @test fmt(str_, separate_kwargs_with_semicolon = true) == str - @test yasfmt1(str_, separate_kwargs_with_semicolon = true) == str - @test yasfmt(str_, separate_kwargs_with_semicolon = true) == str + @test fmt1(str_; separate_kwargs_with_semicolon = true) == str + @test fmt(str_; separate_kwargs_with_semicolon = true) == str + @test yasfmt1(str_; separate_kwargs_with_semicolon = true) == str + @test yasfmt(str_; separate_kwargs_with_semicolon = true) == str str = """ function g(x, y = 1) @@ -2235,10 +2235,10 @@ shortdef1(MatrixT, VectorT = nothing) = nothing shortdef2(MatrixT, VectorT = nothing) where {T} = nothing """ - @test fmt1(str, separate_kwargs_with_semicolon = true) == str - @test fmt(str, separate_kwargs_with_semicolon = true) == str - @test yasfmt1(str, separate_kwargs_with_semicolon = true) == str - @test yasfmt(str, separate_kwargs_with_semicolon = true) == str + @test fmt1(str; separate_kwargs_with_semicolon = true) == str + @test fmt(str; separate_kwargs_with_semicolon = true) == str + @test yasfmt1(str; separate_kwargs_with_semicolon = true) == str + @test yasfmt(str; separate_kwargs_with_semicolon = true) == str str_ = """ x = foo(var = "some really really really really really really really really really really long string") @@ -2248,8 +2248,8 @@ var = "some really really really really really really really really really really long string", ) """ - @test fmt1(str_, separate_kwargs_with_semicolon = true) == str - @test fmt(str_, separate_kwargs_with_semicolon = true) == str + @test fmt1(str_; separate_kwargs_with_semicolon = true) == str + @test fmt(str_; separate_kwargs_with_semicolon = true) == str str_ = """ x = foo(var = "some really really really really really really really really really really long string") @@ -2258,8 +2258,8 @@ x = foo(; var = "some really really really really really really really really really really long string") """ - @test yasfmt1(str_, separate_kwargs_with_semicolon = true) == str - @test yasfmt(str_, separate_kwargs_with_semicolon = true) == str + @test yasfmt1(str_; separate_kwargs_with_semicolon = true) == str + @test yasfmt(str_; separate_kwargs_with_semicolon = true) == str end @testset "`surround_whereop_typeparameters`" begin @@ -2268,24 +2268,24 @@ foo end """ - @test fmt(s, surround_whereop_typeparameters = false) == s + @test fmt(s; surround_whereop_typeparameters = false) == s s = """ function NotificationType(method::AbstractString, ::Type{TPARAM})::R where TPARAM foo end """ - @test fmt(s, surround_whereop_typeparameters = false, m = 100) == s + @test fmt(s; surround_whereop_typeparameters = false, m = 100) == s s = """ NotificationType(method::AbstractString, ::Type{TPARAM}) where TPARAM = foo """ - @test fmt(s, surround_whereop_typeparameters = false) == s + @test fmt(s; surround_whereop_typeparameters = false) == s s = """ NotificationType(method::AbstractString, ::Type{TPARAM})::R where TPARAM = foo """ - @test fmt(s, surround_whereop_typeparameters = false) == s + @test fmt(s; surround_whereop_typeparameters = false) == s end @testset "for_in_replacement" begin @@ -2297,24 +2297,24 @@ for a ∈ b end """ - @test fmt(str_, always_for_in = true, for_in_replacement = "∈") == str + @test fmt(str_; always_for_in = true, for_in_replacement = "∈") == str # generator str_ = "[(i, j) for i = 1:2:10, j = 100:-1:10]" str = "[(i, j) for i ∈ 1:2:10, j ∈ 100:-1:10]" - @test fmt(str_, always_for_in = true, for_in_replacement = "∈") == str + @test fmt(str_; always_for_in = true, for_in_replacement = "∈") == str str_ = "[i for i = 1:10 if i == 2]" str = "[i for i ∈ 1:10 if i == 2]" - @test fmt(str_, always_for_in = true, for_in_replacement = "∈") == str + @test fmt(str_; always_for_in = true, for_in_replacement = "∈") == str str_ = "[(i, j) for i = 1:2:10, j = 100:-1:10]" str = "[(i, j) for i ∈ 1:2:10, j ∈ 100:-1:10]" - @test yasfmt(str_, always_for_in = true, for_in_replacement = "∈") == str + @test yasfmt(str_; always_for_in = true, for_in_replacement = "∈") == str str_ = "[i for i = 1:10 if i == 2]" str = "[i for i ∈ 1:10 if i == 2]" - @test yasfmt(str_, always_for_in = true, for_in_replacement = "∈") == str + @test yasfmt(str_; always_for_in = true, for_in_replacement = "∈") == str @test_throws AssertionError fmt( str_, @@ -2324,15 +2324,15 @@ end @testset "trailing zero" begin - @test fmt("1e-2", trailing_zero = true) == "1e-2" - @test fmt("1f0", trailing_zero = true) == "1.0f0" - @test fmt("1.", trailing_zero = true) == "1.0" - @test fmt("0x1.fp0", trailing_zero = true) == "0x1.fp0" - - @test fmt("1e-2", trailing_zero = false) == "1e-2" - @test fmt("1f0", trailing_zero = false) == "1f0" - @test fmt("1.", trailing_zero = false) == "1." - @test fmt("0x1.fp0", trailing_zero = false) == "0x1.fp0" + @test fmt("1e-2"; trailing_zero = true) == "1e-2" + @test fmt("1f0"; trailing_zero = true) == "1.0f0" + @test fmt("1."; trailing_zero = true) == "1.0" + @test fmt("0x1.fp0"; trailing_zero = true) == "0x1.fp0" + + @test fmt("1e-2"; trailing_zero = false) == "1e-2" + @test fmt("1f0"; trailing_zero = false) == "1f0" + @test fmt("1."; trailing_zero = false) == "1." + @test fmt("0x1.fp0"; trailing_zero = false) == "0x1.fp0" end @testset "noindent blocks" begin @@ -2453,7 +2453,7 @@ end end """ - @test fmt(s_, 4, 92, short_circuit_to_if = true) == s + @test fmt(s_, 4, 92; short_circuit_to_if = true) == s s_ = """ begin @@ -2467,7 +2467,7 @@ end end """ - @test fmt(s_, 4, 11, short_circuit_to_if = true) == s + @test fmt(s_, 4, 11; short_circuit_to_if = true) == s s = """ begin @@ -2478,7 +2478,7 @@ end end """ - @test fmt(s_, 4, 10, short_circuit_to_if = true) == s + @test fmt(s_, 4, 10; short_circuit_to_if = true) == s # > 1 s_ = """ @@ -2493,7 +2493,7 @@ end end """ - @test fmt(s_, 4, 92, short_circuit_to_if = true) == s + @test fmt(s_, 4, 92; short_circuit_to_if = true) == s s_ = """ begin @@ -2507,7 +2507,7 @@ end end """ - @test fmt(s_, 4, 21, short_circuit_to_if = true) == s1 + @test fmt(s_, 4, 21; short_circuit_to_if = true) == s1 s2 = """ begin @@ -2518,15 +2518,15 @@ end end """ - @test fmt(s_, 4, 20, short_circuit_to_if = true) == s2 + @test fmt(s_, 4, 20; short_circuit_to_if = true) == s2 s_ = """ begin (a && b && c) || d end """ - @test fmt(s_, 4, 21, short_circuit_to_if = true) == s1 - @test fmt(s_, 4, 20, short_circuit_to_if = true) == s2 + @test fmt(s_, 4, 21; short_circuit_to_if = true) == s1 + @test fmt(s_, 4, 20; short_circuit_to_if = true) == s2 end @testset "disallow single arg nesting" begin @@ -2547,6 +2547,6 @@ {key => value("String value")} """ - @test fmt(s1, 2, 1, disallow_single_arg_nesting = true) == s2 + @test fmt(s1, 2, 1; disallow_single_arg_nesting = true) == s2 end end diff --git a/test/sciml_style.jl b/test/sciml_style.jl index 57ecc0af..767c2211 100644 --- a/test/sciml_style.jl +++ b/test/sciml_style.jl @@ -96,7 +96,7 @@ foo(x) + goo(y) end """ - @test format_text(str, SciMLStyle(), yas_style_nesting = true) == + @test format_text(str, SciMLStyle(); yas_style_nesting = true) == formatted_str_yas_nesting str = raw""" @@ -106,7 +106,7 @@ # This should be valid with and without `Dict` in `variable_call_indent` @test format_text(str, SciMLStyle()) == str - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == str + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == str str = raw""" SVector(1.0, @@ -114,8 +114,8 @@ """ # Test the same with different callers - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == str - @test format_text(str, SciMLStyle(), variable_call_indent = ["SVector", "test2"]) == str + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == str + @test format_text(str, SciMLStyle(); variable_call_indent = ["SVector", "test2"]) == str str = raw""" Dict{Int, Int}( @@ -137,7 +137,7 @@ # `variable_call_indent` keeps the line break and doesn't align @test format_text(str, SciMLStyle()) == formatted_str1 - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == formatted_str2 + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == formatted_str2 str = raw""" SVector( @@ -158,8 +158,8 @@ """ # Test the same with different callers - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == formatted_str1 - @test format_text(str, SciMLStyle(), variable_call_indent = ["test", "SVector"]) == + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == formatted_str1 + @test format_text(str, SciMLStyle(); variable_call_indent = ["test", "SVector"]) == formatted_str2 str = raw""" @@ -184,9 +184,9 @@ # This is already valid with `variable_call_indent` @test format_text(str, SciMLStyle()) == formatted_str - @test format_text(str, SciMLStyle(), yas_style_nesting = true) == + @test format_text(str, SciMLStyle(); yas_style_nesting = true) == formatted_str_yas_nesting - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == formatted_str + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == formatted_str str = raw""" SomeLongerTypeThanJustString = String @@ -211,7 +211,7 @@ # Here, `variable_call_indent` forces the line break because the line is too long @test format_text(str, SciMLStyle()) == formatted_str1 - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == formatted_str2 + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == formatted_str2 str = raw""" Dict{Int, Int}( @@ -229,7 +229,7 @@ # Test `variable_call_indent` with a comment in a separate line @test format_text(str, SciMLStyle()) == formatted_str - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == formatted_str + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == formatted_str str = raw""" SVector( @@ -247,7 +247,7 @@ # Test the same with different callers @test format_text(str, SciMLStyle()) == formatted_str - @test format_text(str, SciMLStyle(), variable_call_indent = ["SVector"]) == + @test format_text(str, SciMLStyle(); variable_call_indent = ["SVector"]) == formatted_str str = raw""" @@ -272,7 +272,7 @@ # With `variable_call_indent = false`, the comment will be eaten, # see https://github.com/domluna/JuliaFormatter.jl/issues/609 @test format_text(str, SciMLStyle()) == formatted_str1 - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == formatted_str2 + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == formatted_str2 str = raw""" Dict{Int, Int}( # Comment @@ -293,7 +293,7 @@ # Test `variable_call_indent` with both an inline comment after the opening parenthesis # and a comment in a separate line. @test format_text(str, SciMLStyle()) == formatted_str - @test format_text(str, SciMLStyle(), variable_call_indent = ["Dict"]) == formatted_str + @test format_text(str, SciMLStyle(); variable_call_indent = ["Dict"]) == formatted_str str = raw""" SVector( # Comment @@ -312,8 +312,8 @@ """ # Test the same with different callers - @test format_text(str, SciMLStyle(), variable_call_indent = ["test"]) == formatted_str - @test format_text(str, SciMLStyle(), variable_call_indent = ["SVector", "test"]) == + @test format_text(str, SciMLStyle(); variable_call_indent = ["test"]) == formatted_str + @test format_text(str, SciMLStyle(); variable_call_indent = ["SVector", "test"]) == formatted_str str = """ @@ -388,7 +388,7 @@ # xxxxx::SomePrettyLongTypeName{ # Foo # } - @test format_text(str, SciMLStyle(), yas_style_nesting = true) == str + @test format_text(str, SciMLStyle(); yas_style_nesting = true) == str # https://github.com/SciML/JumpProcesses.jl/pull/362#discussion_r1375432275 str_ = """ @@ -416,7 +416,7 @@ Nothing}} body end""" - @test format_text(str_, SciMLStyle(), margin = 1) == str + @test format_text(str_, SciMLStyle(); margin = 1) == str str_ = """ macro (p::CoevolveJumpAggregation{ @@ -443,7 +443,7 @@ Nothing}} body end""" - @test format_text(str_, SciMLStyle(), margin = 1) == str + @test format_text(str_, SciMLStyle(); margin = 1) == str @testset "optimal nesting" begin @testset "function definition" begin @@ -459,8 +459,8 @@ body end """ - @test format_text(str, SciMLStyle(), margin = 41) == fstr - @test format_text(str, SciMLStyle(), margin = 37) == fstr + @test format_text(str, SciMLStyle(); margin = 41) == fstr + @test format_text(str, SciMLStyle(); margin = 37) == fstr fstr = """ function foo(arg1, arg2, arg3, @@ -468,9 +468,9 @@ body end """ - @test format_text(str, SciMLStyle(), margin = 36) == fstr + @test format_text(str, SciMLStyle(); margin = 36) == fstr # should be 30? might be a unnesting off by 1 error - @test format_text(str, SciMLStyle(), margin = 31) == fstr + @test format_text(str, SciMLStyle(); margin = 31) == fstr fstr = """ function foo( @@ -479,8 +479,8 @@ body end """ - @test format_text(str, SciMLStyle(), margin = 29) == fstr - @test format_text(str, SciMLStyle(), margin = 25) == fstr + @test format_text(str, SciMLStyle(); margin = 29) == fstr + @test format_text(str, SciMLStyle(); margin = 25) == fstr fstr = """ function foo( @@ -490,7 +490,7 @@ body end """ - @test format_text(str, SciMLStyle(), margin = 24) == fstr + @test format_text(str, SciMLStyle(); margin = 24) == fstr fstr = """ function foo( @@ -502,7 +502,7 @@ body end """ - @test format_text(str, SciMLStyle(), margin = 18) == fstr + @test format_text(str, SciMLStyle(); margin = 18) == fstr end @testset "vector definition" begin @@ -511,38 +511,38 @@ """ # Fits within the margin - @test format_text(str, SciMLStyle(), margin = 41) == str - @test format_text(str, SciMLStyle(), margin = 37) == str + @test format_text(str, SciMLStyle(); margin = 41) == str + @test format_text(str, SciMLStyle(); margin = 37) == str fstr = """ test = [ arg1, arg2, arg3, arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 36) == fstr - @test format_text(str, SciMLStyle(), margin = 33) == fstr + @test format_text(str, SciMLStyle(); margin = 36) == fstr + @test format_text(str, SciMLStyle(); margin = 33) == fstr fstr = """ test = [arg1, arg2, arg3, arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 32) == fstr + @test format_text(str, SciMLStyle(); margin = 32) == fstr # should be 25? might be a unnesting off by 1 error - @test format_text(str, SciMLStyle(), margin = 26) == fstr + @test format_text(str, SciMLStyle(); margin = 26) == fstr fstr = """ test = [ arg1, arg2, arg3, arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 25) == fstr - @test format_text(str, SciMLStyle(), margin = 21) == fstr + @test format_text(str, SciMLStyle(); margin = 25) == fstr + @test format_text(str, SciMLStyle(); margin = 21) == fstr fstr = """ test = [arg1, arg2, arg3, arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 20) == fstr + @test format_text(str, SciMLStyle(); margin = 20) == fstr # should be 19? might be a unnesting off by 1 error # @test format_text(str, SciMLStyle(), margin = 19) == fstr @@ -552,9 +552,9 @@ arg3, arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 19) == fstr + @test format_text(str, SciMLStyle(); margin = 19) == fstr # should be 15? might be a unnesting off by 1 error - @test format_text(str, SciMLStyle(), margin = 16) == fstr + @test format_text(str, SciMLStyle(); margin = 16) == fstr fstr = """ test = [ @@ -563,7 +563,7 @@ arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 15) == fstr + @test format_text(str, SciMLStyle(); margin = 15) == fstr fstr = """ test = [arg1, @@ -572,7 +572,7 @@ arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 14) == fstr + @test format_text(str, SciMLStyle(); margin = 14) == fstr fstr = """ test = [ @@ -582,7 +582,7 @@ arg4, arg5] """ - @test format_text(str, SciMLStyle(), margin = 13) == fstr + @test format_text(str, SciMLStyle(); margin = 13) == fstr end end @@ -594,5 +594,5 @@ # This should be valid with and without `yas_style_nesting` @test format_text(str, SciMLStyle()) == str - @test format_text(str, SciMLStyle(), yas_style_nesting = true) == str + @test format_text(str, SciMLStyle(); yas_style_nesting = true) == str end diff --git a/test/yas_style.jl b/test/yas_style.jl index 56cdfa0b..c6a1c087 100644 --- a/test/yas_style.jl +++ b/test/yas_style.jl @@ -165,14 +165,14 @@ str = """ comp = [a * b for a in 1:10, b in 11:20]""" - @test yasfmt(str_, 2, length(str_) - 1, always_for_in = true) == str - @test yasfmt(str_, 2, 34, always_for_in = true) == str + @test yasfmt(str_, 2, length(str_) - 1; always_for_in = true) == str + @test yasfmt(str_, 2, 34; always_for_in = true) == str str = """ comp = [a * b for a in 1:10, b in 11:20]""" - @test yasfmt(str_, 2, 33, always_for_in = true) == str + @test yasfmt(str_, 2, 33; always_for_in = true) == str str = """ comp = [a * @@ -181,20 +181,20 @@ 1:10, b in 11:20]""" - @test yasfmt(str_, 2, 1, always_for_in = true) == str + @test yasfmt(str_, 2, 1; always_for_in = true) == str str_ = "comp = Typed[a * b for a in 1:10, b in 11:20]" str = """ comp = Typed[a * b for a in 1:10, b in 11:20]""" - @test yasfmt(str_, 2, length(str_) - 1, always_for_in = true) == str - @test yasfmt(str_, 2, 39, always_for_in = true) == str + @test yasfmt(str_, 2, length(str_) - 1; always_for_in = true) == str + @test yasfmt(str_, 2, 39; always_for_in = true) == str str = """ comp = Typed[a * b for a in 1:10, b in 11:20]""" - @test yasfmt(str_, 2, 38, always_for_in = true) == str + @test yasfmt(str_, 2, 38; always_for_in = true) == str str = """ comp = Typed[a * @@ -203,14 +203,14 @@ 1:10, b in 11:20]""" - @test yasfmt(str_, 2, 1, always_for_in = true) == str + @test yasfmt(str_, 2, 1; always_for_in = true) == str str_ = "foo(arg1, arg2, arg3) == bar(arg1, arg2, arg3)" str = """ foo(arg1, arg2, arg3) == bar(arg1, arg2, arg3)""" # change in default behavior - @test yasfmt(str, 2, length(str_), join_lines_based_on_source = false) == str_ + @test yasfmt(str, 2, length(str_); join_lines_based_on_source = false) == str_ @test yasfmt(str_, 2, length(str_) - 1) == str @test yasfmt(str_, 2, 24) == str @@ -305,15 +305,15 @@ str = """ var = fcall(arg1, arg2, arg3, # comment arg4, arg5)""" - @test yasfmt(str_, 4, 80, join_lines_based_on_source = false) == str - @test yasfmt(str_, 4, 29, join_lines_based_on_source = false) == str + @test yasfmt(str_, 4, 80; join_lines_based_on_source = false) == str + @test yasfmt(str_, 4, 29; join_lines_based_on_source = false) == str str = """ var = fcall(arg1, arg2, arg3, # comment arg4, arg5)""" - @test yasfmt(str_, 4, 28, join_lines_based_on_source = false) == str - @test yasfmt(str_, 4, 23, join_lines_based_on_source = false) == str + @test yasfmt(str_, 4, 28; join_lines_based_on_source = false) == str + @test yasfmt(str_, 4, 23; join_lines_based_on_source = false) == str str = """ var = fcall(arg1, @@ -341,8 +341,8 @@ end for a = 1:10, # comment 2 b = 11:20, c = 300:400]""" - @test yasfmt(str_, 2, 80, join_lines_based_on_source = false) == str - @test yasfmt(str_, 2, 35, join_lines_based_on_source = false) == str + @test yasfmt(str_, 2, 80; join_lines_based_on_source = false) == str + @test yasfmt(str_, 2, 35; join_lines_based_on_source = false) == str str = """ comp = [begin @@ -449,7 +449,7 @@ (b_hat - y_hat) * delta[i] + (b - y) * delta_hat[i] - delta[i] * delta_hat[i] for i = 1:8]""" - @test yasfmt(str_, 2, 60, join_lines_based_on_source = false) == str + @test yasfmt(str_, 2, 60; join_lines_based_on_source = false) == str end @testset "issue 237" begin @@ -467,14 +467,14 @@ @testset "issue 320" begin str_ = "[x[i] for i = 1:length(x)]" str = "[x[i] for i in 1:length(x)]" - @test yasfmt(str_, 4, 92, always_for_in = true) == str + @test yasfmt(str_, 4, 92; always_for_in = true) == str end @testset "issue 321 - exponential inline comments !!!" begin str = """ scaled_ticks, mini, maxi = optimize_ticks(scale_func(lmin), scale_func(lmax); k_min=4, # minimum number of ticks k_max=8)""" - @test yasfmt(str, 4, 92, whitespace_in_kwargs = false) == str + @test yasfmt(str, 4, 92; whitespace_in_kwargs = false) == str end @testset "issue 355 - vcat/typedvcat" begin @@ -580,7 +580,7 @@ # This should be valid with and without `Dict` in `variable_call_indent` @test format_text(str, YASStyle()) == str - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == str + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == str str = raw""" SVector(1.0, @@ -588,8 +588,8 @@ """ # Test the same with different callers - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == str - @test format_text(str, YASStyle(), variable_call_indent = ["SVector", "test2"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == str + @test format_text(str, YASStyle(); variable_call_indent = ["SVector", "test2"]) == str str = raw""" @@ -611,7 +611,7 @@ # `variable_call_indent` keeps the line break and doesn't align @test format_text(str, YASStyle()) == formatted_str1 - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == formatted_str2 str = raw""" @@ -632,9 +632,9 @@ """ # Test the same with different callers - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == formatted_str1 - @test format_text(str, YASStyle(), variable_call_indent = ["test", "SVector"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["test", "SVector"]) == formatted_str2 str = raw""" @@ -651,7 +651,7 @@ # This is already valid with `variable_call_indent` @test format_text(str, YASStyle()) == formatted_str - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == str + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == str str = raw""" SomeLongerTypeThanJustString = String @@ -676,8 +676,8 @@ # Here, `variable_call_indent` forces the line break because the line is too long. # For some reason, this has to be formatted twice. @test format_text(str, YASStyle()) == formatted_str1 - intermediate_str = format_text(str, YASStyle(), variable_call_indent = ["Dict"]) - @test format_text(intermediate_str, YASStyle(), variable_call_indent = ["Dict"]) == + intermediate_str = format_text(str, YASStyle(); variable_call_indent = ["Dict"]) + @test format_text(intermediate_str, YASStyle(); variable_call_indent = ["Dict"]) == formatted_str2 str = raw""" @@ -696,7 +696,7 @@ # Test `variable_call_indent` with a comment in a separate line @test format_text(str, YASStyle()) == str - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == formatted_str + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == formatted_str str = raw""" SVector( @@ -714,7 +714,7 @@ # Test the same with different callers @test format_text(str, YASStyle()) == str - @test format_text(str, YASStyle(), variable_call_indent = ["SVector"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["SVector"]) == formatted_str str = raw""" @@ -738,7 +738,7 @@ # With `variable_call_indent = false`, the comment will be eaten, # see https://github.com/domluna/JuliaFormatter.jl/issues/609 @test format_text(str, YASStyle()) == formatted_str1 - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == formatted_str2 str = raw""" @@ -768,7 +768,7 @@ # Test `variable_call_indent` with both an inline comment after the opening parenthesis # and a comment in a separate line. @test format_text(str, YASStyle()) == formatted_str1 - @test format_text(str, YASStyle(), variable_call_indent = ["Dict"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["Dict"]) == formatted_str2 str = raw""" @@ -796,9 +796,9 @@ """ # Test the same with different callers - @test format_text(str, YASStyle(), variable_call_indent = ["test"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["test"]) == formatted_str1 - @test format_text(str, YASStyle(), variable_call_indent = ["SVector", "test"]) == + @test format_text(str, YASStyle(); variable_call_indent = ["SVector", "test"]) == formatted_str2 end end