Skip to content

Commit

Permalink
Also trim trailing semicolon in do and (mutable )struct
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Aug 22, 2024
1 parent 282377e commit 9f8bcab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3279,7 +3279,7 @@ function remove_trailing_semicolon(ctx::Context, node::Node)
r = remove_trailing_semicolon_block(ctx, node)
return r
end
if !(!is_leaf(node) && kind(node) in KSet"if elseif quote function for let while macro try catch finally else")
if !(!is_leaf(node) && kind(node) in KSet"if elseif quote function for let while macro try catch finally else do struct")
return nothing
end
if kind(node) === K"quote" && JuliaSyntax.has_flags(node, JuliaSyntax.COLON_QUOTE)
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ end
"""
for prefix in (
"begin", "quote", "for i in I", "let", "let x = 1", "while cond",
"if cond", "macro f()", "function f()",
"if cond", "macro f()", "function f()", "f() do", "f() do x",
)
@test format_string("$(prefix)\n$(body)\nend") == "$prefix\n$(bodyfmt)\nend"
end
Expand All @@ -1184,6 +1184,10 @@ end
format_string("try\n$(bodyfmt)\ncatch err\n$(bodyfmt)\nfinally\n$(bodyfmt)\nend")
@test format_string("try\n$(body)\ncatch err\n$(body)\nelse\n$(body)\nend") ==
format_string("try\n$(bodyfmt)\ncatch err\n$(bodyfmt)\nelse\n$(bodyfmt)\nend")
for mut in ("", "mutable ")
@test format_string("$(mut)struct A\na::Int;\nend") ==
"$(mut)struct A\n a::Int\nend"
end
# Top-level semicolons are kept (useful if you want to supress output in various
# contexts)
let str = """
Expand Down

0 comments on commit 9f8bcab

Please sign in to comment.