sway
sway copied to clipboard
Parts of the formatter use destructive methods
We should avoid using .pop()
and the like, and find work arounds for the current use cases that implement it. This will help us avoid creating unparsable code resulting in vague errors.
Good point! What would be a typical workaround for lists of arguments with a separator where the separator should not appear at the end, i.e. foo, bar, baz
? I think that's a common use case for .pop()
in the formatter: we add the separator at each iteration and then .pop()
the last one after the loop.
Good point! What would be a typical workaround for lists of arguments with a separator where the separator should not appear at the end, i.e.
foo, bar, baz
? I think that's a common use case for.pop()
in the formatter: we add the separator at each iteration and then.pop()
the last one after the loop.
In an instance where do want to get rid of something like this, I think we should at least perform some kind of check before committing to it. In that specific instance we can use a peekable iterator and check for the last remaining item in a list.
It's tricky, the AST gives us sometimes an optional final value, and other times the final value is in the primary list of items.