Skip to content

Commit d3a2225

Browse files
authored
Allow empty files in EOF newline task (#309)
Per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403, a file is allowed to have zero or more lines where a line is terminated by a newline character.
1 parent 8899002 commit d3a2225

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

wpiformat/test/test_eofnewline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_eofnewline():
2424

2525
# Empty file
2626
test.add_input("./Test.h", "")
27-
test.add_output("\n", True)
27+
test.add_output("", True)
2828

2929
test_output = file_appendix + os.linesep
3030

wpiformat/wpiformat/eofnewline.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
"""This task ensures that the file has exactly one EOF newline."""
1+
"""This task ensures that the file has zero EOF newlines if it's empty or one EOF newline."""
22

33
from wpiformat.task import PipelineTask
44

55

66
class EofNewline(PipelineTask):
77
def run_pipeline(self, config_file, name, lines):
8-
return lines.rstrip() + super().get_linesep(lines), True
8+
lines = lines.rstrip()
9+
if lines:
10+
return lines + super().get_linesep(lines), True
11+
else:
12+
return lines, True

0 commit comments

Comments
 (0)