#!/usr/bin/env python3 """Fix ConstantName checkstyle violations: rename logger to LOG.""" import xml.etree.ElementTree as ET import re import sys def get_files_with_violations(xml_path: str) -> set[str]: tree = ET.parse(xml_path) root = tree.getroot() files = set() for file_elem in root.iter("file"): for error in file_elem.findall("error"): if ( error.get("source") == "com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck" ): files.add(file_elem.get("name")) return files def fix_file(path: str) -> int: with open(path, "r", encoding="utf-8") as f: content = f.read() original = content # Replace declaration: private static final Logger logger -> private static final Logger LOG content = re.sub( r"(\bprivate\s+static\s+final\s+Logger\s+)logger\b", r"\1LOG", content ) # Replace all word-boundary usages of 'logger' -> 'LOG' # This handles: logger.debug, logger.info, logger.warn, logger.error, logger, # LoggerDecorator.warn(logger, ...), etc. content = re.sub(r"\blogger\b", "LOG", content) if content != original: with open(path, "w", encoding="utf-8") as f: f.write(content) return 1 return 0 def main(): xml_path = "build/reports/checkstyle/main.xml" files = get_files_with_violations(xml_path) print(f"Found {len(files)} files with ConstantName violations") fixed = 0 for path in sorted(files): result = fix_file(path) if result: fixed += 1 print(f" Fixed: {path}") print(f"\nTotal files fixed: {fixed}") return 0 if __name__ == "__main__": sys.exit(main())