feat(app-controller): modularize handlers and enforce 1-space indentation
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
|
||||
import sys
|
||||
|
||||
def fix_indentation(file_path):
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
fixed_lines = []
|
||||
indent_map = {0: 0}
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
stripped = line.lstrip()
|
||||
if not stripped:
|
||||
fixed_lines.append('\n')
|
||||
continue
|
||||
|
||||
old_indent = len(line) - len(stripped)
|
||||
|
||||
# Remove larger indents from map if we dedent below them
|
||||
for k in list(indent_map.keys()):
|
||||
if k > old_indent:
|
||||
del indent_map[k]
|
||||
|
||||
if old_indent not in indent_map:
|
||||
# Find the closest smaller indent
|
||||
known = sorted([k for k in indent_map.keys() if k < old_indent])
|
||||
parent_new = indent_map[max(known)]
|
||||
indent_map[old_indent] = parent_new + 1
|
||||
|
||||
new_indent = indent_map[old_indent]
|
||||
fixed_lines.append(' ' * new_indent + stripped)
|
||||
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(fixed_lines)
|
||||
|
||||
if __name__ == '__main__':
|
||||
fix_indentation('src/app_controller.py')
|
||||
print("Indentation fixed v3.")
|
||||
Reference in New Issue
Block a user