Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions analysis/quality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
def analyze_quality(function_details):
issues = []

for function in function_details:
if function["lines"] > 30:
issues.append(
f"{function['name']} (starts at Line {function['start_line']}): long function"
)

if function["arguments"] > 5:
issues.append(
f"{function['name']} (starts at Line {function['start_line']}): too many arguments"
)

if function["complexity"] > 10:
issues.append(
f"{function['name']} (starts at Line {function['start_line']}): "
f"high complexity ({function['complexity']})"
)

return issues


def calculate_health_score(function_details, todos, fixmes):
score = 100

for function in function_details:
if function["lines"] > 30:
score -= 5
if function["arguments"] > 5:
score -= 3
if function["complexity"] > 10:
score -= 5

score -= todos
score -= fixmes

return max(0, score)


def get_health_rating(score):
if score >= 90:
return "Excellent"
elif score >= 75:
return "Good"
elif score >= 50:
return "Needs Improvement"
else:
return "Poor"
56 changes: 5 additions & 51 deletions analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

from analysis.lines import analyze_lines
from analysis.ast_analysis import analyze_ast
from analysis.quality import (
analyze_quality,
calculate_health_score,
get_health_rating,
)


def generate_json_report(results, output_file="codebase_report.json"):
Expand Down Expand Up @@ -179,57 +184,6 @@ def parse_python_file(source, file):
return None


def analyze_quality(function_details):
issues = []

for function in function_details:
if function["lines"] > 30:
issues.append(
f"{function['name']} (starts at Line {function['start_line']}): long function"
)

if function["arguments"] > 5:
issues.append(
f"{function['name']} (starts at Line {function['start_line']}): too many arguments"
)

if function["complexity"] > 10:
issues.append(
f"{function['name']} (starts at Line {function['start_line']}): "
f"high complexity ({function['complexity']})"
)

return issues


def calculate_health_score(function_details, todos, fixmes):
score = 100

for function in function_details:
if function["lines"] > 30:
score -= 5
if function["arguments"] > 5:
score -= 3
if function["complexity"] > 10:
score -= 5

score -= todos
score -= fixmes

return max(0, score)


def get_health_rating(score):
if score >= 90:
return "Excellent"
elif score >= 75:
return "Good"
elif score >= 50:
return "Needs Improvement"
else:
return "Poor"


def generate_codebase_summary(results):
if not results:
print("No valid Python files found.")
Expand Down
Loading