-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalyze_code.py
More file actions
72 lines (57 loc) · 2.44 KB
/
analyze_code.py
File metadata and controls
72 lines (57 loc) · 2.44 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
#!/usr/bin/env python3
"""Analyze code for potential issues."""
import ast
import os
from collections import defaultdict
def analyze_code():
"""Find code quality issues."""
missing_docstrings = defaultdict(list)
uses_eval = []
uses_exec = []
missing_type_hints = defaultdict(list)
for root, dirs, files in os.walk('mathplot'):
if 'tests' in root or 'import_conversion_backup' in root:
continue
for file in files:
if not file.endswith('.py'):
continue
filepath = os.path.join(root, file)
try:
with open(filepath, 'r') as f:
content = f.read()
tree = ast.parse(content)
# Check for class and function docstrings
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
if not ast.get_docstring(node) and not node.name.startswith('_'):
if node.name not in ['register', 'unregister', 'execute', 'invoke', 'poll', 'draw']:
missing_docstrings[filepath].append(node.name)
# Check for eval/exec usage
for node in ast.walk(tree):
if isinstance(node, ast.Call):
if isinstance(node.func, ast.Name):
if node.func.id == 'eval':
uses_eval.append(filepath)
elif node.func.id == 'exec':
uses_exec.append(filepath)
except Exception as e:
print(f"Error analyzing {filepath}: {e}")
print("=" * 60)
print("CODE QUALITY ANALYSIS")
print("=" * 60)
if uses_eval:
print("\n⚠️ Files using eval():")
for f in set(uses_eval):
print(f" {f}")
if uses_exec:
print("\n⚠️ Files using exec():")
for f in set(uses_exec):
print(f" {f}")
if missing_docstrings:
print("\n📝 Functions missing docstrings:")
for filepath, funcs in sorted(missing_docstrings.items()):
if len(funcs) > 0:
print(f" {filepath}: {', '.join(funcs[:3])}{' ...' if len(funcs) > 3 else ''}")
print("\n" + "=" * 60)
if __name__ == '__main__':
analyze_code()