chores: Add spaces to tabs fix for mixed

This commit is contained in:
Miodrag Milanovic
2026-08-21 14:33:46 +02:00
parent a34d3baae9
commit a55d987b3a
2 changed files with 45 additions and 0 deletions
+7
View File
@@ -28,3 +28,10 @@ repos:
- id: mixed-line-ending
args: [--fix,lf]
- id: trailing-whitespace
- repo: local
hooks:
- id: indent-fix
name: Convert indentation spaces to tabs
entry: python3 misc/spaces_to_tabs.py
language: system
files: \.(cc|h)$
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
import re
import sys
from pathlib import Path
changed = False
for filename in sys.argv[1:]:
path = Path(filename)
try:
text = path.read_text()
except UnicodeDecodeError:
continue
# Determine whether this file uses tabs for indentation.
uses_tabs = any(
re.match(r"^\t+", line)
for line in text.splitlines()
)
if not uses_tabs:
continue
new_text = re.sub(
r"^(?: {4})+",
lambda m: "\t" * (len(m.group()) // 4),
text,
flags=re.MULTILINE,
)
if new_text != text:
path.write_text(new_text)
changed = True
print(f"Converted indentation to tabs: {filename}")
sys.exit(1 if changed else 0)