Definitions
What the numbers mean
Every metric here is a proxy for something you actually care about, and every one of them can be gamed. This page says what each is computed from and where it stops being useful.
Lines, code, blank
LINES is every line in the file. CODE is the
lines that are neither blank nor comment. Blank lines are lines that are
empty after stripping whitespace.
For Python this is exact: the file is run through the standard library tokenizer, so a comment is a comment token and a docstring — a string that opens a logical line — counts as a comment too. A trailing comment does not turn its line into a comment line; the line has code on it, so it counts as code.
For every other language the counting is a heuristic over line prefixes and block delimiters. It handles ordinary source correctly and gets confused by comment markers inside string literals. Treat non-Python counts as good to within a percent or two, not as exact.
Comment density
DOC% is comment lines as a share of non-blank lines. It is
reported because a file with no comments at all is worth a glance, not
because a higher number is better. Past roughly fifteen per cent the
figure stops meaning anything: commented-out code counts as a comment, and
so does a licence header pasted at the top of every file.
Cyclomatic complexity
CPLX is the classic count of decision points plus one, summed
over the file. Counted as decisions: if and elif,
for and while loops, except
handlers, conditional expressions, each additional operand of a boolean
operator, each condition in a comprehension, and each match
case. else is not a decision — it is the branch you already
counted.
Python complexity comes from the parsed syntax tree, so it is exact.
Everything else is counted by matching keywords and the &&,
|| and ? operators against lines that are not
comments. That over-counts a file that mentions those tokens in strings
and under-counts languages with pattern matching. It is sound for ranking
files within one repository and unsound as an absolute figure.
JSON output also carries max_function for Python: the worst
single function in the file. A file with complexity 90 spread evenly over
thirty functions is ordinary. One with complexity 90 where a single
function accounts for 40 of it is a different problem, and the file total
alone will not tell you which you have.
Change frequency
CHG is the number of commits that touched the file in the
window, and AUTH the number of distinct author addresses among
them. Both come from git log --no-merges --numstat. Merge
commits are excluded so that a merge does not count every file in the
branch a second time. Binary files are skipped, because
--numstat cannot report line counts for them.
Renames. History is followed only as far as Git reports
it inside the window. A file renamed just before the window opens looks
new and therefore quiet, which is exactly backwards. If a result
surprises you, widen --since and see whether it moves.
Author counts are addresses, not people. One contributor committing from a
laptop and from CI is two authors; a team sharing a service account is one.
Read AUTH as "how many identities touch this", which is still
informative, rather than as a headcount.
Hotspot score
HOT is the product of complexity and change frequency, each
first divided by the largest value in the same run, scaled to 0–100. The
highest ranked file is therefore always exactly 100.
The reasoning is that neither number is interesting alone. A complicated file nobody touches is not costing anyone anything this quarter — it is only expensive the day someone has to change it. A file that changes constantly but is trivial is fine; that is what a configuration file looks like. The overlap is where the cost lands: difficult code that you are forced to keep touching.
The score is relative to the run. Because both inputs
are normalised against the top file, scores cannot be compared between
two repositories, and they cannot be compared between two runs with
different --since windows. What they are for is comparing
the same repository with the same window at two points in time — that is
the comparison the hosted service drew charts of.
What this does not measure
Not correctness, not test coverage, not architecture, not whether the code is any good. A well-factored file under heavy development will rank high and deserve to be left alone; a quiet file can be the worst thing in the repository. The output is a list of places to look, in a useful order. It is not a judgement, and it was never intended to be aggregated into a single number for a dashboard — which is why Metrica never produced one.
Languages recognised
Files with any other extension are ignored entirely; they are not counted as zero, they simply do not appear.
| Language | Extensions | Analysis |
|---|---|---|
| Python | .py .pyi | Parsed |
| C | .c .h | Heuristic |
| C++ | .cc .cpp .hpp | Heuristic |
| Go | .go | Heuristic |
| Rust | .rs | Heuristic |
| Java | .java | Heuristic |
| JavaScript | .js .mjs | Heuristic |
| TypeScript | .ts .tsx | Heuristic |
| Ruby | .rb | Heuristic |
| PHP | .php | Heuristic |
| Shell | .sh .bash | Heuristic |
| SQL | .sql | Heuristic |
| Lua | .lua | Heuristic |
Adding a language is a two-line change to the table at the top of the module: the display name, its line comment tokens and its block comment delimiters. Nothing else in the tool is language-specific except the Python path.