Browse Source

Fix whitespace before comment in operator formatting (#89)

pull/90/head
Fredrik Ekre 1 year ago committed by GitHub
parent
commit
d9a27b9d62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      src/runestone.jl
  2. 3
      test/runtests.jl

5
src/runestone.jl

@ -149,6 +149,8 @@ function spaces_around_x(ctx::Context, node::Node, is_x::F, n_leaves_per_x::Int @@ -149,6 +149,8 @@ function spaces_around_x(ctx::Context, node::Node, is_x::F, n_leaves_per_x::Int
looking_for_x = false
n_x_leaves_visited = 0
peek(kids, i) = i < length(kids) ? kind(kids[i + 1]) : nothing
for (i, kid) in pairs(kids)
if kind(kid) === K"NewlineWs" ||
(i == 1 && kind(kid) === K"Whitespace")
@ -160,7 +162,8 @@ function spaces_around_x(ctx::Context, node::Node, is_x::F, n_leaves_per_x::Int @@ -160,7 +162,8 @@ function spaces_around_x(ctx::Context, node::Node, is_x::F, n_leaves_per_x::Int
any_changes && push!(kids′, kid)
looking_for_whitespace = false
elseif looking_for_whitespace
if kind(kid) === K"Whitespace" && span(kid) == 1
if (kind(kid) === K"Whitespace" && span(kid) == 1) ||
(kind(kid) === K"Whitespace" && peek(kids, i) === K"Comment" && peek(kids, i + 1) === K"NewlineWs")
# All good, just advance the IO
accept_node!(ctx, kid)
any_changes && push!(kids′, kid)

3
test/runtests.jl

@ -182,8 +182,9 @@ end @@ -182,8 +182,9 @@ end
@test format_string("$(sp)a$(sp)$(op)$(sp)\nb$(sp)") ==
"$(sp)a $(op)\n b$(sp)"
# a op # comment \n b
minspace = sp == "" ? " " : sp
@test format_string("$(sp)a$(sp)$(op)$(sp)# comment\nb$(sp)") ==
"$(sp)a $(op) # comment\n b$(sp)"
"$(sp)a $(op)$(minspace)# comment\n b$(sp)"
end
# Exceptions to the rule: `:`, `..`, and `^`
# a:b

Loading…
Cancel
Save