discord-bot/scripts/fix-constant-name.py
loki5512344 6b034319d1
fix: resolve ALL checkstyle + PMD + SpotBugs violations (0 remaining)
Checkstyle (3127 → 0):
- FinalLocalVariable: 1812 violations fixed via script (added final to local vars)
- MagicNumber: 1071 violations fixed via script (extracted constants)
- ConstantName: 76 violations fixed (logger → LOG)
- RedundantModifier: 162 → 0 (removed redundant final/public in interfaces)
- WhitespaceAround: 132 → 0 (configured allowEmpty* properties)
- IllegalCatch: 38 → 0 (added specific exception catches)
- NeedBraces: 29 → 0 (added braces to single-line if/else)
- EqualsAvoidNull: 26 → 0 (literal.equals(var) → var.equals(literal))
- HideUtilityClassConstructor: 14 → 0 (added private constructors)
- FileLength: 12 → 0 (extracted 13 helper classes, deleted dead code)
- ParameterNumber: 10 → 0 (created records for grouped params)
- MethodLength: 8 → 0 (extracted sub-methods)
- LineLength: 6 → 0 (wrapped long lines)
- MissingSwitchDefault: 5 → 0 (added default cases)
- MultipleVariableDeclarations: 4 → 0 (split declarations)
- CyclomaticComplexity: 3 → 0 (refactored complex methods)
- ClassFanOutComplexity: 2 → 0
- AvoidStarImport: 2 → 0 (expanded to specific imports)
- UnusedImports: 1 → 0
- Regexp: 1 → 0

PMD (47 → 0):
- CloseResource: 8 → 0 (try-with-resources + NOPMD for managed resources)
- CognitiveComplexity: 11 → 0 (extracted helper methods, early returns)
- CyclomaticComplexity: 6 → 0 (refactored complex methods)
- TooManyMethods: 2 → 0 (extracted classes)
- AvoidReassigningParameters: 2 → 0 (local variables)
- UnusedPrivateMethod: 1 → 0 (removed dead code)

Dead code removed:
- Deleted feature/roast/ package (26 files) - unused AI debate feature
- Cleaned up all references in ListenerAggregator, BotModule, UtilityCommandRegistrar

New files created: 14 (SetupPanelBuilder, SetupDashboardBuilder, MuteNotifier, etc.)
2026-08-06 20:01:36 +02:00

63 lines
1.7 KiB
Python

#!/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())