mirror of
https://github.com/luongnv89/claude-howto.git
synced 2026-06-05 22:36:34 +02:00
540508f392
- Add pre-commit hooks: Ruff lint/format, Bandit security scan, YAML/TOML validation - Add GitHub Actions CI workflow: lint, security, test, and build jobs - Configure Ruff and Bandit in pyproject.toml - Add pytest test suite for build_epub.py (25 tests) - Fix code issues: exception chaining, httpx timeout, formatting - Add requirements.txt and requirements-dev.txt
36 lines
896 B
Python
36 lines
896 B
Python
#!/usr/bin/env python3
|
|
import re
|
|
import sys
|
|
|
|
|
|
def analyze_code_metrics(code):
|
|
"""Analyze code for common metrics."""
|
|
|
|
# Count functions
|
|
functions = len(re.findall(r"^def\s+\w+", code, re.MULTILINE))
|
|
|
|
# Count classes
|
|
classes = len(re.findall(r"^class\s+\w+", code, re.MULTILINE))
|
|
|
|
# Average line length
|
|
lines = code.split("\n")
|
|
avg_length = sum(len(l) for l in lines) / len(lines) if lines else 0
|
|
|
|
# Estimate complexity
|
|
complexity = len(re.findall(r"\b(if|elif|else|for|while|and|or)\b", code))
|
|
|
|
return {
|
|
"functions": functions,
|
|
"classes": classes,
|
|
"avg_line_length": avg_length,
|
|
"complexity_score": complexity,
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
with open(sys.argv[1]) as f:
|
|
code = f.read()
|
|
metrics = analyze_code_metrics(code)
|
|
for key, value in metrics.items():
|
|
print(f"{key}: {value:.2f}")
|