#!/usr/bin/env python3 """Fix misplaced 'using StellaOps.TestKit;' statements in C# files.""" import os import re from pathlib import Path def fix_file(filepath: Path) -> bool: """Fix a single file. Returns True if modified.""" content = filepath.read_text(encoding='utf-8-sig') lines = content.split('\n') # Check if this line appears misplaced (after line 30, which is definitely past usings) misplaced_indices = [] for i, line in enumerate(lines): if line.strip() == 'using StellaOps.TestKit;' and i > 25: misplaced_indices.append(i) if not misplaced_indices: return False # Remove the misplaced lines new_lines = [line for i, line in enumerate(lines) if i not in misplaced_indices] # Write back new_content = '\n'.join(new_lines) filepath.write_text(new_content, encoding='utf-8') return True def main(): src_dir = Path(r'E:\dev\git.stella-ops.org\src') fixed_count = 0 for cs_file in src_dir.rglob('*.cs'): try: if fix_file(cs_file): fixed_count += 1 print(f"Fixed: {cs_file}") except Exception as e: print(f"Error processing {cs_file}: {e}") print(f"\nFixed {fixed_count} files") if __name__ == '__main__': main()