Skip to content

Commit

Permalink
fix #728
Browse files Browse the repository at this point in the history
  • Loading branch information
domluna committed Jun 7, 2023
1 parent bd6e2f6 commit a37fd19
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,23 @@ function print_tree(
(nodes[i+2].typ === Block || nodes[i+2].typ === Begin)
if noindent
add_indent!(nodes[i+2], s, -s.opts.indent)
# this captures the trailing comment is not captured as being part of the block
if i + 4 <= length(nodes) && nodes[i+4].typ === NOTCODE
nodes[i+4].indent -= s.opts.indent
end
else
n.indent = nodes[i+2].indent
end
n.indent = nodes[i+2].indent
elseif i > 2 && (nodes[i-2].typ === Block || nodes[i-2].typ === Begin)
if noindent
add_indent!(nodes[i+2], s, -s.opts.indent)
add_indent!(nodes[i-2], s, -s.opts.indent)
else
n.indent = nodes[i-2].indent
end
n.indent = nodes[i-2].indent
end

if noindent
n.indent -= s.opts.indent
end
end

Expand Down
22 changes: 22 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1660,4 +1660,26 @@
"""
@test fmt(s, 4, 92, always_use_return = true) == s
end
@testset "728" begin
s = """
begin
#! format: noindent
# This is OK
function foo end
# This is not
end
"""
@test fmt(s, 4, 92) == s

s = """
begin
#! format: noindent
end
"""
@test fmt(s, 4, 92) == s
end
end

0 comments on commit a37fd19

Please # to comment.