Skip to content

Commit c6656ec

Browse files
committed
Only add newline before #ifdef block if other lines preceded it
1 parent 8151725 commit c6656ec

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

wpiformat/test/test_includeorder.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,12 @@ def test_includeorder():
499499
test.add_input("./Test.h", "// #included here" + os.linesep)
500500
test.add_output("// #included here" + os.linesep, False, True)
501501

502+
# Ensure extra newline isn't inserted between #pragma and #ifdef
503+
test.add_input("./Test.h",
504+
"#pragma once" + os.linesep + \
505+
os.linesep + \
506+
"#ifdef _MSC_VER" + os.linesep + \
507+
"#endif" + os.linesep)
508+
test.add_latest_input_as_output(True)
509+
502510
test.run(OutputType.FILE)

wpiformat/wpiformat/includeorder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ def header_sort(self, config_file, lines_list, file_name, start, end,
268268
else:
269269
# Treat #ifdef as barrier and flush includes
270270
output_list.extend(self.write_headers(includes))
271-
output_list.append("")
271+
if output_list:
272+
# Only add newline if content already exists in
273+
# output_list that needs to be delimited from
274+
# the #ifdef
275+
output_list.append("")
272276
includes = [[], [], [], [], []]
273277

274278
output_list.append(ifdef)

0 commit comments

Comments
 (0)