From e3a4a9e1c62885d3c5ba710f2e38c0c8a90e0e24 Mon Sep 17 00:00:00 2001 From: Azaucifer <47237500+Azaucifer@users.noreply.github.com> Date: Fri, 4 Sep 2026 16:24:29 +0530 Subject: [PATCH] Refactor quality analysis into module --- analysis/quality.py | 49 +++++++++++++++++++++++++++++++++++++++ analyzer.py | 56 ++++----------------------------------------- 2 files changed, 54 insertions(+), 51 deletions(-) create mode 100644 analysis/quality.py diff --git a/analysis/quality.py b/analysis/quality.py new file mode 100644 index 0000000..7f00bb6 --- /dev/null +++ b/analysis/quality.py @@ -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" \ No newline at end of file diff --git a/analyzer.py b/analyzer.py index 9224fff..586bdf0 100644 --- a/analyzer.py +++ b/analyzer.py @@ -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"): @@ -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.")