Skip to content

Commit

Permalink
Allow no space before comment after (, [, {, fixes #81.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Oct 27, 2024
1 parent f9450a5 commit 0840bf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3451,7 +3451,9 @@ function spaces_around_comments(ctx::Context, node::Node)
push!(kids′, kid′)
end
accept_node!(ctx, kid′)
prev_kid_ends_with_ws = kind(kid′) in KSet"Whitespace NewlineWs" ||
# Note: This allows (but doesn't require) no space after opening brackets, see
# https://github.com/fredrikekre/Runic.jl/issues/81
prev_kid_ends_with_ws = kind(kid′) in KSet"Whitespace NewlineWs ( { [" ||
(ll = last_leaf(kid′); ll !== nothing && kind(ll) in KSet"Whitespace NewlineWs")
end
# Reset the stream and return
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ end
@test format_string("(a,$(sp)# comment\nb + b)") ==
"(\n a,$(csp)# comment\n b + b,\n)"
@test format_string("if c$(sp)# a\n b\nend") == "if c$(csp)# a\n b\nend"
# Allow no space after opening brackets
# (https://github.com/fredrikekre/Runic.jl/issues/81)
for (o, c) in (("(", ")"), ("[", "]"), ("{", "}"))
@test format_string("$(o)$(sp)#= a =#$(sp)$(c)") == "$(o)$(sp)#= a =#$(c)"
end
end
let str = "a = 1 # a comment\nab = 2 # ab comment\n"
@test format_string(str) == str
Expand Down

0 comments on commit 0840bf4

Please sign in to comment.