Skip to content

Scoring

Michael L. McKnight edited this page Dec 5, 2026 · 1 revision

Scoring

Canonical source: docs/scoring.md. Both numbers are computed in core/base.py after duplicates are removed and disabled_rules is applied.

Each file gets two independent numbers: a quality score that covers all findings, and a security grade that covers only security findings.

Quality score (0–100)

quality_score = 100 × exp( −P / (600 × max(KLOC, 0.1)) )
  P    = sum of issue weights: CRITICAL 20, HIGH 10, MEDIUM 5, LOW 2, INFO 0.5
  KLOC = code lines (non-blank, non-comment) / 1000
  • No findings → 100. The score is always within 0–100 and rounded to one decimal.
  • It is size-adjusted: the same findings cost less in a bigger file. Files under 100 code lines are treated as 100 lines (KLOC is floored at 0.1), so tiny snippets are not judged too harshly or too leniently.
  • 600 is the decay constant: a 1,000-line file with P = 600 scores 100 × e⁻¹ ≈ 36.8.

Security grade (A–F)

security_score = max(0, 100 − (30×CRITICAL + 15×HIGH + 5×MEDIUM + 1×LOW))     # security category only
grade          = A ≥ 90, B ≥ 80, C ≥ 70, D ≥ 60, else F
caps           = any CRITICAL → at best D;  any HIGH → at best B

The security score is not size-adjusted: one injection flaw is just as serious in a 10-line file as in a 10,000-line file. INFO findings are ignored.

Worked examples (from the docs)

README Python snippet (5 lines): 2 HIGH (hardcoded password, eval) + 2 LOW (missing docstring, unused variable).

P = 2×10 + 2×2 = 24;  KLOC → 0.1
quality = 100 × exp(−24 / 60) = 67.0
security: the two HIGH findings are security → 100 − 30 = 70 → C (the HIGH cap of B does not lower C)

examples/fixdemo/app.py (34 code lines): 3 CRITICAL, 2 HIGH, 1 MEDIUM, 4 LOW.

P = 3×20 + 2×10 + 5 + 4×2 = 93;  KLOC → 0.1
quality = 100 × exp(−93 / 60) = 21.2
security: 3 CRITICAL + 2 HIGH = 120 → score 0 → F

The same 10 findings in a 2,000-line file: 100 × exp(−93 / 1200) = 92.5. The security grade stays F.

Using scores in CI

code-cleaner analyze src/ --min-score 80 --fail-on high

--min-score fails when any file scores below the threshold; --fail-on fails when any finding is at or above the given severity. Many teams start with --fail-on critical and tighten it over time. See Integrations.

Clone this wiki locally