diff --git a/src/passes.jl b/src/passes.jl index cdc09d3c6..2d3d2cbc0 100644 --- a/src/passes.jl +++ b/src/passes.jl @@ -256,6 +256,13 @@ end function short_to_long_function_def!(fst::FST, s::State) (fst[1].typ !== Call && fst[1].typ !== Where) && return false + # do not apply if parent is a function or macro definition + parent_is( + fst.ref[], + n -> is_function_or_macro_def(n) || n.head == :macrocall; + ignore = n -> is_block(n), + ) && return false + # 3 cases # # case 1 diff --git a/src/styles/sciml/nest.jl b/src/styles/sciml/nest.jl index 01a6287e1..9a1ad9fca 100644 --- a/src/styles/sciml/nest.jl +++ b/src/styles/sciml/nest.jl @@ -38,14 +38,7 @@ function n_binaryopcall!(ss::SciMLStyle, fst::FST, s::State; indent::Int = -1) line_margin = s.line_offset + length(fst) + fst.extra_margin if line_margin > s.opts.margin && fst.ref !== nothing && - ( - !parent_is( - fst.ref[], - n -> is_function_or_macro_def(n) || n.head == :macrocall; - ignore = n -> is_block(n), - ) - ) - CSTParser.defines_function(fst.ref[]) + CSTParser.defines_function(fst.ref[]) transformed = short_to_long_function_def!(fst, s) transformed && nest!(style, fst, s) end diff --git a/test/issues.jl b/test/issues.jl index e921c5082..d4784555a 100644 --- a/test/issues.jl +++ b/test/issues.jl @@ -1706,4 +1706,25 @@ """ @test fmt(str_, 4, 92, join_lines_based_on_source = true) == str end + + @testset "753" begin + str_ = """ + using ModelingToolkit + @mtkmodel A begin + @variables begin + i(t) = 0.0, [description = "Line longer than the char limit of 94 characters", unit = u"A"] + end + end + """ + str = """ + using ModelingToolkit + @mtkmodel A begin + @variables begin + i(t) = 0.0, + [description = "Line longer than the char limit of 94 characters", unit = u"A"] + end + end + """ + @test format_text(str_, SciMLStyle()) == str + end end