Browse Source

Allow no space before comment after `(`, `[`, `{`, fixes #81.

pull/84/head
Fredrik Ekre 1 year ago
parent
commit
0840bf44e7
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 4
      src/runestone.jl
  2. 5
      test/runtests.jl

4
src/runestone.jl

@ -3451,7 +3451,9 @@ function spaces_around_comments(ctx::Context, node::Node) @@ -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

5
test/runtests.jl

@ -87,6 +87,11 @@ end @@ -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

Loading…
Cancel
Save