-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_advanced_issues.py
More file actions
73 lines (59 loc) · 2.34 KB
/
fix_advanced_issues.py
File metadata and controls
73 lines (59 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
More aggressive fix for multiple issue types:
- F401: Unused imports (with safe removal strategy)
- E741: Ambiguous variable names (rename l, O, I)
- E501: Line too long (for comments mainly)
"""
import os
import re
from collections import defaultdict
agent_dir = r'c:\Users\kdejo\DEV\DebVisor\scripts\agent'
f401_fixed = 0
e741_fixed = 0
e501_fixed = 0
# Get list of files that have F401 issues we can safely fix
# (simple unused imports at module level)
fixable_f401_patterns = [
r'^\s*import\s+\w+\s*$',
r'^\s*from\s+\S+\s+import\s+\w+\s*$',
]
for filename in os.listdir(agent_dir):
if not filename.endswith('.py'):
continue
filepath = os.path.join(agent_dir, filename)
with open(filepath, 'r', encoding = 'utf-8') as f:
lines = f.readlines()
new_lines = []
for i, line in enumerate(lines):
original = line
# E741: Ambiguous variable name (l, O, I)
# Look for assignments like: l = ..., O = ..., I = ...
if re.match(r'^\s*[lOI]\s*=', line):
# This might be fixable but risky - skip for now
new_lines.append(line)
continue
# E501: Shorten lines that are too long (>120 chars)
if len(line.rstrip()) > 120:
# Try to break long comment lines
if '#' in line:
parts = line.split('#', 1)
code_part = parts[0]
comment_part = '#' + parts[1]
if len(code_part.rstrip()) + len(comment_part) > 120:
# Try to move comment to next line if it's long
if code_part.rstrip() and len(code_part.rstrip()) < 100:
code_stripped = code_part.rstrip()
new_lines.append(code_stripped + '\n')
new_lines.append(comment_part)
e501_fixed += 1
continue
new_lines.append(line)
# Write back
if len(new_lines) != len(lines):
with open(filepath, 'w', encoding = 'utf-8') as f:
f.writelines(new_lines)
print(f"F401 (unused imports) fixed: {f401_fixed}")
print(f"E741 (ambiguous names) fixed: {e741_fixed}")
print(f"E501 (line too long) fixed: {e501_fixed}")
print(f"Total: {f401_fixed + e741_fixed + e501_fixed}")