summaryrefslogtreecommitdiff
path: root/format.py
diff options
context:
space:
mode:
authorcadmic <cadmic24@gmail.com>2025-01-20 14:30:54 -0800
committerGitHub <noreply@github.com>2025-01-20 17:30:54 -0500
commit5346c978a949864fd84bc0587dfed794998cede7 (patch)
tree9f45cbb2026bda506d8572a1c4fd3ec66d529bc6 /format.py
parent11b7bf2914ff62523110f6fc82c59184a2a8684a (diff)
format.py: Allow empty files (#2434)
Diffstat (limited to 'format.py')
-rwxr-xr-xformat.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/format.py b/format.py
index a5faa79c9..f95885344 100755
--- a/format.py
+++ b/format.py
@@ -97,8 +97,7 @@ def run_clang_apply_replacements(tmp_dir: str):
def cleanup_whitespace(file: str):
"""
- Remove whitespace at the end of lines,
- ensure the file ends with an empty line.
+ Remove whitespace at the end of lines, and ensure all lines end with a newline.
"""
file_p = Path(file)
contents = file_p.read_text(encoding="UTF-8")
@@ -108,7 +107,7 @@ def cleanup_whitespace(file: str):
if n_subst != 0:
modified = True
- if not contents.endswith("\n"):
+ if contents and not contents.endswith("\n"):
contents += "\n"
modified = True