Skip to content

Commit

Permalink
Fix spaces around assignment in for-loop specifications
Browse files Browse the repository at this point in the history
`for`-loop nodes are of kind K"=" even when using `in`. This patch fixes
the predicate for `spaces_around_assignments` to include K"in" as an
option. Note that when using `in` spaces are required, but the pass
is still useful to remove spaces when there are more than one.
  • Loading branch information
fredrikekre committed May 26, 2024
1 parent a0ba874 commit 8e13c29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,8 @@ function spaces_around_assignments(ctx::Context, node::JuliaSyntax.GreenNode)
if !(is_assignment(node) && !JuliaSyntax.is_trivia(node))
return nothing
end
return spaces_around_x(ctx, node, is_assignment)
# for-loop nodes are of kind K"=" even when `in` is used so we need to
# include K"in" in the predicate too.
is_x = x -> is_assignment(x) || JuliaSyntax.kind(x) === K"in"
return spaces_around_x(ctx, node, is_x)
end
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,9 @@ end
@test format_string("a =+ c") == "a = + c"
# Short form function definitions
@test format_string("sin(π)=cos(pi)") == "sin(π) = cos(pi)"
# For loop nodes are assignment, even when using `in`
@test format_string("for i=1:10\nend\n") == "for i = 1 : 10\nend\n"
@test format_string("for i =1:10\nend\n") == "for i = 1 : 10\nend\n"
@test format_string("for i = 1:10\nend\n") == "for i = 1 : 10\nend\n"
@test format_string("for i in 1:10\nend\n") == "for i in 1 : 10\nend\n"
end

0 comments on commit 8e13c29

Please sign in to comment.