Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 37 ยท Coverage and Technical Debt

Technical Debt and the A-to-E Ratings in SonarQube

Learn how SonarQube estimates technical debt, computes the debt ratio and the Maintainability, Reliability and Security ratings from A to E, with runnable calculators.

Every code smell in SonarQube carries a remediation effort: the time a developer would need to fix it. Add the efforts of all open maintainability issues and you get the project's technical debt, shown in minutes, hours or days. Compare that debt with the estimated cost of writing the code in the first place and you get the debt ratio, which becomes the Maintainability rating.

This lesson explains the numbers, the three ratings, and how to use them without being misled. The server is not available on this site; the TryIt blocks are stand-ins that reproduce the arithmetic.

Debt as a measure

Rules have a remediation function. Many use a constant (for example 5 minutes for a simple naming issue) and some scale with a value, such as the amount by which a function exceeds the cognitive complexity threshold. Your project's debt is the sum over all open code smells, available as the metric sqale_index (in minutes). The name comes from the SQALE method that inspired the model.

New code has new_technical_debt: the debt of smells introduced since the new code period started.

Debt is an estimate. It is useful for comparing modules and tracking direction over time, not for planning a sprint to the minute.

Debt ratio and the Maintainability rating

TEXT
debt ratio = remediation cost / development cost
development cost = lines of code x cost per line

The default cost per line is 30 minutes (property sonar.technicalDebt.developmentCost, which an administrator can change). So 10,000 lines cost 300,000 minutes to develop, as far as the formula is concerned.

The ratio is mapped to a letter:

Rating Debt ratio
A 0% to 5%
B 6% to 10%
C 11% to 20%
D 21% to 50%
E above 50%

The metric keys are sqale_debt_ratio and sqale_rating; the new-code versions are new_sqale_debt_ratio (or new_maintainability_rating). Administrators can change the thresholds under the rating grid settings.

A worked example: a service has 12,000 lines of code, so development cost = 360,000 minutes. Its code smells add up to 2 days, counting 8-hour days = 960 minutes. Ratio = 960 / 360,000 = 0.27%. Rating A. Even a few days of debt are tiny compared with the effort that built the code.

JS Stand-in: debt ratio and Maintainability rating

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The remediation display uses 8-hour days, so 960 minutes shows as 2d, as the helper imitates.

Reliability and Security ratings

The other two ratings do not use ratios. They look at the worst open issue:

Rating Reliability (bugs) Security (vulnerabilities)
A 0 bugs 0 vulnerabilities
B at least 1 minor at least 1 minor
C at least 1 major at least 1 major
D at least 1 critical at least 1 critical
E at least 1 blocker at least 1 blocker

In recent releases (the Clean Code taxonomy, SonarQube Server 10.2 and later) issues carry an impact with Low, Medium or High severity per software quality (Security, Reliability, Maintainability) instead of the older Blocker-to-Info scale, and the ratings are derived from those impact levels in the same spirit: the worst open issue decides the letter. Your server's documentation lists the exact mapping for your version.

Ratings on new code behave identically but only consider issues in new code. That is why one old bug does not block a new pull request.

JS Stand-in: Reliability or Security rating from issues

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Reading the trend, not just the letter

  • A flat A rating on a growing codebase means you are paying debt as you go.
  • Debt that grows while the ratio stays at A means the project is also growing; check new_technical_debt per pull request instead.
  • A rating of E on a legacy project is not a reason to freeze work. Apply Clean as You Code: keep the new code at A and fix old code when you touch it.

Paying the debt down

  1. Sort the Issues list by effort (the Maintainability quality, then sort by remediation) to find large debts.
  2. Look for rules that explain many issues. Fixing one pattern, for example unused imports, can clear hundreds of minutes.
  3. Fix issues in the files you already change for features.
  4. Re-evaluate the rule set in the quality profile if a rule produces noise that your team has agreed to ignore (see the quality profiles lesson in the Rules and Quality Gates chapter of this track).
  5. Track sqale_index weekly with the Web API (see Web API and automation).

Pitfalls

  • Comparing teams by raw debt. A bigger codebase has more debt; use the ratio.
  • Gaming the number by marking issues "Accepted" or "False positive" in bulk. Those statuses remove issues from the count, so reserve them for real exceptions.
  • Believing the effort is exact. Remediation times are defaults tuned across many projects.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. A project has 5,000 lines, the default cost of 30 min per line, and 9,000 minutes of debt. Which Maintainability rating does it get?

    Development cost = 150,000 min; ratio = 9,000 / 150,000 = 6%, which falls in the 6-10% band, so B.
  2. 2. What decides the Reliability rating?

    Reliability uses the severity of the worst open bug; Security uses vulnerabilities in the same way.
  3. 3. What is sqale_index?

    sqale_index is the technical debt, measured in minutes.

Summary

  • Technical debt is the summed remediation effort of open code smells.
  • Debt ratio divides debt by an estimated development cost (lines x 30 minutes by default) and maps to A through E.
  • Reliability and Security ratings come from the worst open bug or vulnerability.
  • Judge new code separately from legacy code, and treat the numbers as guidance.

Next: Duplications and complexity