---
title: "Code quality"
description: "What the code-quality scanner measures (function complexity, length, parameters), its thresholds, how it reports findings and how to turn it on."
---

The code-quality scanner measures every function in a repository or source
tree and reports the files whose functions are hard to maintain. It is
**maintainability, not security**: its findings are never risk-scored, never
count toward a remediation SLA or an asset's grade, and their severity is only
ever *info* (`none`) or *low*.

It runs [lizard](https://github.com/terryyin/lizard) 1.26.1 (MIT) as an
engine, alongside the vulnerability, secret and static-analysis engines, in the
same repository or filesystem scan. The code is
`backend/internal/scanner/lizard`.

## What is measured

For each function, lizard reports three numbers, and the scanner compares them
with fixed thresholds:

| Measure | What it counts | Reported (info) when over | Low severity when over |
|---|---|---|---|
| Cyclomatic complexity | Independent paths through the function: 1, plus one for each `if`, loop, `case`, `catch`, `&&`, `\|\|` and similar | 15 | 25 |
| Length | Lines of code in the function, without blank lines and comments | 100 | 200 |
| Parameters | Declared parameters | 6 | 10 |

"Over" is strictly greater: a function with a complexity of exactly 15 is not
reported. A file's severity is low when any of its functions is over a low
threshold, otherwise info. The thresholds are the same for every
organization; they cannot be changed per organization yet.

Not measured: duplicated code (lizard can find it, but its duplicate search is
slow on large repositories), cognitive complexity, nesting depth, comment
density, and test coverage.

lizard parses the languages its 1.26.1 release lists, among them C and C++,
C#, Java, Kotlin, Scala, JavaScript, TypeScript (including TSX and Vue), Python,
Go, Rust, Swift, Objective-C, Ruby, PHP, Lua, Dart and Solidity. Its parsers
read structure rather than compiling, so an unusual construct can be measured
slightly differently from a compiler's view.

### What is skipped

- Paths the repository's own `.gitignore` excludes.
- `node_modules`, `vendor`, `third_party`, `dist` and `build` directories,
  `.git`, and `*.min.js` files: dependencies and build output nobody
  refactors.
- Any skip paths the scan request names.

## How findings are reported

One finding per **file**, of kind `code_quality`, with the identifier
`quality.functions` (its [catalogue entry](/concepts/check-catalogue)). The
title says how many of the file's functions are over a threshold, and the
detail lists the ten worst (highest complexity first) with their start and end
lines, complexity, lines of code, parameter count and which thresholds each is
over.

A scan reports at most **200 files**, worst first (low severity before info,
then by highest complexity). When more are over a threshold, the scan carries a
warning saying how many were left out.

A file's finding is identified by its path alone, so editing a function in it
keeps the same finding (and its triage state) with updated numbers. When no
function in the file is over a threshold any more, the next scan that runs the
scanner resolves it.

## Where to see it

- The **repository page** (Assets, then the repository) has a *Code quality*
  card: how many files and functions are over a threshold, the highest
  complexity and the longest function, and the five worst functions, each
  linked to its finding. It says *Not measured* when the last scan did not run
  the scanner, rather than showing a clean result.
- **Code security → Code quality** lists the findings across every repository.
- The findings API: `GET /api/v1/findings?kind=code_quality`.

## Enabling it

The scanner needs the `lizard` program, which the published
`trustowl-backend` image does not include. `backend/Dockerfile.sast`, the
analyser image built on top of the published one for
[static analysis](/configuration/static-analysis), installs a pinned lizard in
its own Python environment. There is no setting: a worker whose image has
`lizard` on `PATH` offers the scanner, and one without it logs that code
quality is unavailable at startup and does not offer it.

```bash
docker build -f backend/Dockerfile -t trustowl-backend:local .
docker build -f backend/Dockerfile.sast \
  --build-arg BASE_IMAGE=trustowl-backend:local \
  -t trustowl-backend:sast .
```

Repository targets are cloned with the same built-in git client the
vulnerability scanner uses, including for private repositories with a stored
credential or a linked GitHub App. The scanner refuses a repository in offline
mode (`SCANNER_OFFLINE`), because measuring it needs a clone; a filesystem
target is measured offline.

### Turning it on for an organization

Like static analysis, it is off until an organization selects it. An
administrator ticks *Code quality* in **Settings → Data and evidence →
Repository scanners** and saves, or over the API:

```bash
curl -X PUT https://app.trustivan.com/api/v1/settings/scanners/repository \
  -H "Authorization: Bearer $TRUSTIVAN_API_KEY" -H "Content-Type: application/json" \
  -d '{"scanners": ["vulnerability", "secret", "sbom", "quality"]}'
```

A single scan can also ask for it by naming `quality` in its `scanners`. A
deployment that cannot run lizard refuses `quality` with `400`.
