yapf
yapf copied to clipboard
Fix unexpected whitespace removal outside line range
trafficstars
- save the whitespace prefix in the pytree node even for those occurring with comments
- disable the comment splicer's removal of trailing whitespace
- add back the whitespace before emitting unformatted line
- remove trailing whitespace in comments for enabled lines later when printing
TODO:
- extensive testing is necessary as this method is like a hack
- this still will remove trailing whitespace in line just before line range and will ignore trailing whitespace in last line of line range
Could you give an example of what this is fixing?
The example is in the linked issue.
Resolve conflicts
After a long while of using this with only the problems mentioned in my first post, I've found a further problem that occurs with the following:
def main():
if 1:
if 1:
pass
# extra
elif 1:
pass
pass
Applying the modified yapf on anywhere except including the extra comment line, we will get extra trailing space on the line before the extra comment line. I've not figured out the bug yet.