Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions yapf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def main(argv):

source = [line.rstrip() for line in original_source]
source[0] = _removeBOM(source[0])
# filter all the tuples with empty space
source = list(filter(None, source))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this change, as it seems overly broad. For instance, if there are disabled sections, we don't want to remove the newlines from them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks! Yeah, makes sense to not format the disabled sections. I'll try to see if I can prevent the commented section from filtering.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bwendling, I have added a util function that filters out the comment sections while removing the new lines. Kindly let me know for any feedback.


try:
reformatted_source, _ = yapf_api.FormatCode(
Expand Down
8 changes: 8 additions & 0 deletions yapftests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,11 @@ def testHelp(self):
self.assertIn('indent_width=4', help_message)
self.assertIn('The number of spaces required before a trailing comment.',
help_message)
def testExtraBlankLine(self):
code = 'if True:\n\n\n\n\t print(2)'
yapf_code = 'if True:\n print(2)\n'
with patched_input(code):
with captured_output() as (out, _):
ret = yapf.main([])
self.assertEqual(ret, 0)
self.assertEqual(out.getvalue(), yapf_code)