chore: Fix pre commit hook failing on empty file (#2766)

This commit is contained in:
Sergey Kuznetsov
2025-11-10 14:35:19 +00:00
committed by GitHub
parent a5b1dcfe55
commit c0eedd273d
2 changed files with 11 additions and 1 deletions

View File

@@ -44,8 +44,13 @@ def fix_colon_spacing(cpp_content: str) -> str:
def fix_indentation(cpp_content: str) -> str:
if "JSON(" not in cpp_content:
return cpp_content
lines = cpp_content.splitlines()
ends_with_newline = cpp_content.endswith('\n')
def find_indentation(line: str) -> int:
return len(line) - len(line.lstrip())
@@ -66,7 +71,11 @@ def fix_indentation(cpp_content: str) -> str:
break
lines[i] = lines[i][by_how_much:] if by_how_much > 0 else " " * (-by_how_much) + lines[i]
return "\n".join(lines) + "\n"
result = "\n".join(lines)
if ends_with_newline:
result += "\n"
return result
def process_file(file_path: Path, dry_run: bool) -> bool: