From 03a94495b828a53509e00bf9d3e7082326f3ca1e Mon Sep 17 00:00:00 2001 From: Dominique Luna Date: Tue, 19 Sep 2023 14:47:40 -0400 Subject: [PATCH] fix #757 --- Project.toml | 2 +- src/align.jl | 9 +++++++++ test/issues.jl | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 96ce8795f..8d5ea8dff 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JuliaFormatter" uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899" authors = ["Dominique Luna "] -version = "1.0.36" +version = "1.0.37" [deps] CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f" diff --git a/src/align.jl b/src/align.jl index f08299772..62a6d1fa8 100644 --- a/src/align.jl +++ b/src/align.jl @@ -202,6 +202,14 @@ function align_struct!(fst::FST) nlen = length(n[1]) ind = findfirst(x -> x.typ === OPERATOR, n.nodes) + # issue 757 + # "foo + # """ + # a::B + # + # This is parsed as a concatenated string of "foo" and "" + ind === nothing && continue + ws = n[ind].line_offset - (n.line_offset + nlen) push!(g, n, i, n[ind].line_offset, nlen, ws) @@ -216,6 +224,7 @@ function align_struct!(fst::FST) binop = n[end] nlen += length(binop[1]) ind = findfirst(x -> x.typ === OPERATOR, binop.nodes) + ind === nothing && continue ws = binop[ind].line_offset - (n.line_offset + nlen) push!(g, binop, i, binop[ind].line_offset, nlen, ws) diff --git a/test/issues.jl b/test/issues.jl index d4784555a..c943d3c2f 100644 --- a/test/issues.jl +++ b/test/issues.jl @@ -1727,4 +1727,15 @@ """ @test format_text(str_, SciMLStyle()) == str end + + @testset "757" begin + str = """ + struct Foo + \"foo + \"\"\" + foo::String + end + """ + @test fmt(str, 4, 92, align_struct_field = true) == str + end end