code-metrics-analysis▌
aj-geddes/useful-ai-prompts · updated Apr 8, 2026
Measure and analyze code quality metrics to identify complexity, maintainability issues, and areas for improvement.
Code Metrics Analysis
Table of Contents
Overview
Measure and analyze code quality metrics to identify complexity, maintainability issues, and areas for improvement.
When to Use
- Code quality assessment
- Identifying refactoring candidates
- Technical debt monitoring
- Code review automation
- CI/CD quality gates
- Team performance tracking
- Legacy code analysis
Quick Start
Minimal working example:
import * as ts from "typescript";
import * as fs from "fs";
interface ComplexityMetrics {
cyclomaticComplexity: number;
cognitiveComplexity: number;
linesOfCode: number;
functionCount: number;
classCount: number;
maxNestingDepth: number;
}
class CodeMetricsAnalyzer {
analyzeFile(filePath: string): ComplexityMetrics {
const sourceCode = fs.readFileSync(filePath, "utf-8");
const sourceFile = ts.createSourceFile(
filePath,
sourceCode,
ts.ScriptTarget.Latest,
true,
);
const metrics: ComplexityMetrics = {
cyclomaticComplexity: 0,
cognitiveComplexity: 0,
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| TypeScript Complexity Analyzer | TypeScript Complexity Analyzer |
| Python Code Metrics (using radon) | Python Code Metrics (using radon) |
| ESLint Plugin for Complexity | ESLint Plugin for Complexity |
| CI/CD Quality Gates | CI/CD Quality Gates |
Best Practices
✅ DO
- Monitor metrics over time
- Set reasonable thresholds
- Focus on trends, not absolute numbers
- Automate metric collection
- Use metrics to guide refactoring
- Combine multiple metrics
- Include metrics in code reviews
❌ DON'T
- Use metrics as sole quality indicator
- Set unrealistic thresholds
- Ignore context and domain
- Punish developers for metrics
- Focus only on one metric
- Skip documentation
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.8★★★★★41 reviews- ★★★★★Benjamin Liu· Dec 28, 2024
Registry listing for code-metrics-analysis matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Mia Zhang· Dec 24, 2024
Useful defaults in code-metrics-analysis — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Advait Srinivasan· Dec 12, 2024
I recommend code-metrics-analysis for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Camila Abebe· Nov 27, 2024
code-metrics-analysis is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Benjamin White· Nov 19, 2024
Useful defaults in code-metrics-analysis — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Rahul Santra· Nov 7, 2024
code-metrics-analysis is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Advait Farah· Nov 3, 2024
code-metrics-analysis reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Pratham Ware· Oct 26, 2024
Keeps context tight: code-metrics-analysis is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Naina Gonzalez· Oct 22, 2024
Registry listing for code-metrics-analysis matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Aarav Khanna· Oct 18, 2024
Keeps context tight: code-metrics-analysis is the kind of skill you can hand to a new teammate without a long onboarding doc.
showing 1-10 of 41