fix: consistent whitespace around go keywords #371
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is an attempted fix for #354. The issue seemed to be caused by the recursive nature of
writeNodes
. When callingwriteNodes()
fromwriteIfExpression()
,writeForExpression()
, andwriteSwitchExpression()
, the last iteration of the loop inwriteNodes()
wouldn't correctly know the next node in the node list.For example:
would produce a node list of
[element]->[if expression]->[element]
with[if expression]
having a node list of[element]
. On the final iteration of the loop inwriteNodes()
when writing the node list of[if expression]
, the next element would benil
instead of the next[element]
node. This was messing with theisInlineOrText()
function as passing it anil
node will return false so they expected whitespace isn't added.I have fixed the issue by having
writeNodes()
also take in anext
parser.Node
so when the function is called recursively fromwriteIfExpression()
,writeForExpression()
, andwriteSwitchExpression()
, the next node in the node list can be passed in and used when relevant. If the function isn't being called recursively, we can still pass innil
as thenext
node and thenwriteNodes()
will work as it did previously. If we pass in a nonnil
next
towriteNodes()
, it will be used as thenext
value whennextNode
isnil
ie. on the last iteration of the loop.I've also added a few test for whitespace in if, switch and for expressions.
If there is anything that looks incorrect in this or if there is anything you'd like me to change, please let me know.