Browse Source

Fix trailing comma in single item lists with generators

Closes #16.
pull/19/head
Fredrik Ekre 1 year ago
parent
commit
6df3f7ae3a
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 4
      src/runestone.jl
  2. 3
      test/runtests.jl

4
src/runestone.jl

@ -384,6 +384,10 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -384,6 +384,10 @@ function spaces_in_listlike(ctx::Context, node::Node)
kind(kids[first_item_idx::Int]) !== K"parameters"
# TODO: May also have to check for K"where" and K"::" in the lineage above
require_trailing_comma = true
elseif kind(node) in KSet"call" && n_items == 1 && kind(kids[first_item_idx::Int]) === K"generator"
# https://github.com/fredrikekre/Runic.jl/issues/16
# TODO: There is probably a more generic pattern for the check above.
require_trailing_comma = false
elseif kind(node) in KSet"bracescat parens"
require_trailing_comma = false # Leads to parser error
elseif kind(node) in KSet"block"

3
test/runtests.jl

@ -316,6 +316,9 @@ end @@ -316,6 +316,9 @@ end
@test format_string("(a = A;;)") == "(a = A)"
@test format_string("(;;)") == format_string("( ; ; )") == "(;;)"
@test format_string("(;)") == format_string("( ; )") == "(;)"
# https://github.com/fredrikekre/Runic.jl/issues/16
@test format_string("(i for i in\nI)") == "(\n i for i in\n I\n)"
@test format_string("f(i for i in\nI)") == "f(\n i for i in\n I\n)"
end
@testset "whitespace around ->" begin

Loading…
Cancel
Save