Code quality scorecard: dimensions, targets, enforcement.
- User
Code quality scorecard: dimensions, targets, enforcement.
- Assistant
Code Quality Scorecard
A code quality scorecard is a standardized framework to measure, track, and improve code quality across a codebase or team. It defines dimensions (key metrics/categories), targets (achievable benchmarks), and enforcement (tools/processes to automate and gate compliance). This ensures consistent, high-quality code that is reliable, secure, maintainable, and scalable.
The scorecard below is a practical template for most software teams (e.g., using languages like JavaScript, Python, Java, Go). Customize thresholds based on team maturity, language, and domain. Aim for 80%+ overall scorecard compliance as a team goal.
Dimensions, Targets, and Scoring
Each dimension includes:
- Metrics: Measurable indicators.
- Targets: Green (pass ≥), Yellow (warning), Red (fail <).
- Weight: Relative importance (total 100%).
Dimension Description Key Metrics Targets (Green/Yellow/Red) Weight Reliability Code's ability to handle errors and failures gracefully. - Unit test coverage- Integration test coverage- Bug density (bugs/kloc) ≥80% / 60-80% / <60%≥70% / 50-70% / <50%<0.5 / 0.5-1 / >1 20% Security Protection against vulnerabilities and exploits. - Static Application Security Testing (SAST) score- Secrets in code- Dependency vulnerabilities ≥90% / 70-90% / <70% (e.g., SonarQube)0 / 1-2 / >20 high/crit / 1-3 / >3 (e.g., OWASP) 20% Performance Efficiency in resource usage and speed. - Cyclomatic complexity (per function)- Response time (ms)- Memory/CPU usage ≤10 / 10-15 / >15≤200ms (p95) / 200-500 / >500≤80% baseline / 80-100% / >100% 15% Maintainability Ease of understanding, modifying, and extending code. - Code duplication (% of codebase)- Technical debt ratio- Cognitive complexity ≤5% / 5-10% / >10%≤5% / 5-10% / >10%≤15 / 15-25 / >25 20% Readability Code that's easy to read and self-documenting. - Lines of code per function- Naming convention compliance- Comment density (where needed) ≤50 / 50-100 / >100≥95% / 80-95% / <80%20-30% / 10-20% / <10% or >40% 10% Testability Code designed for easy testing. - Mockability score- Test execution time- Mutation testing score ≥90% / 70-90% / <70%≤5s per 1k tests / 5-10s / >10s≥80% / 60-80% / <60% 10% Architecture Adherence to design principles and standards. - SOLID principle violations- Layering/dependency violations- API contract compliance ≤2% violations / 2-5% / >5%0 cycles / 1-2 / >2100% / 95-100% / <95% 5% Overall Score Calculation: Weighted average of dimension scores. Target: ≥85% green for PR merges.
Enforcement Mechanisms
Enforce via automated gates, reviews, and culture. Integrate into CI/CD (e.g., GitHub Actions, Jenkins, GitLab CI).
Mechanism Tools/Processes How It Works Coverage Automated Linting & Formatting ESLint, Prettier, Black, SonarLint, Checkov Run on pre-commit (husky) and CI. Fail builds on red thresholds. Auto-fix where possible. Readability, Maintainability (100% enforcement) Static Analysis SonarQube, CodeQL, Semgrep, DeepSource Scan full repo/PR diffs. Block merges <80% overall. Weekly reports. All dimensions (90% automated) Testing & Security Scans Jest/Pytest (coverage), OWASP ZAP/Snyk (deps/sec), Mutation Testing (PITest/stryker) Require ≥80% coverage in CI. Fail PRs on failures/high vulns. Reliability, Security, Testability (100% gate) Code Reviews GitHub/GitLab PRs with required checks Mandatory reviews (2+ approvers). Checklist includes scorecard. Block on yellow/red. Architecture, Readability (human + bot) CI/CD Gates Quality Gate in SonarQube, Branch Protection Rules PRs must pass all checks. Promote to prod only on green scorecard. Full scorecard (100% enforced) Monitoring & Dashboards SonarCloud, CodeClimate, Grafana Real-time dashboards. Alerts on regressions. Quarterly audits. All (proactive) Cultural Enforcement OKRs, Pair Programming, Tech Debt Sprints Tie to perf reviews. Allocate 20% sprint time for refactoring. All (behavioral) Implementation Roadmap
- Week 1: Select tools, baseline current score.
- Week 2-4: Set up CI gates, enforce on new code.
- Ongoing: Retroactively refactor (tech debt quota), track trends.
This scorecard reduces defects by 40-60% and speeds onboarding. Track ROI via DORA metrics (deploy frequency, lead time). Questions? Let's debug your setup. 🕵️♂️
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.