Commit 6197398ec1

6197398ec1d74de46a877a85f275eb65a86d0d92

parent: 0b4b200f53

Unsigned

cmc <hello@cleberg.net> · 2026-10-25 05:49 UTC

Gate file complexity, and say why function complexity stays off (!31)

A9. Both gates were disabled next to a 4,000-line view model, with "left to
review rather than counted" as the reason. One is on now; the other stays off
with evidence rather than a shrug.

## file_complexity: on, as a ratchet

Measured today, twenty-two files exceed qlty's default. The ten worst:

| file | complexity |
|---|---|
| ResultSectionViews | 386 |
| DomainViewModel | 370 |
| ContentView | 306 |
| CloudSyncService | 198 |
| DomainDataPortabilityService | 146 |
| WatchlistView | 146 |
| AuditViews | 128 |
| DomainReportExporter | 114 |
| SettingsViews | 112 |
| WorkflowsView | 107 |

Splitting twenty-two files is not this finding's job, and a threshold picked to
make them all pass would gate nothing. So the threshold is 400 — just above
today's worst case. It fails anything past that, which stops the three big
files growing, and it comes down as files are genuinely split.

Verified both directions: clean at 400, and at 380 `ResultSectionViews` (386)
fails. A gate I had not watched fail is a gate I would not trust.

## function_complexity: off, with a measurement

qlty's Swift parser mis-attributes it here. `existingShare`
(`CloudSyncService:336`) is eight lines and seven statements; qlty reports
complexity **184 spanning lines 336–1515** — the whole rest of the file.
`fetchZoneChanges` in the same file is measured correctly (31, lines
1049–1135), so the fault is inconsistent rather than systematic.

That leaves no usable threshold. At or under 184 the artifact is the only
failure and the one real result is drowned; above 184 nothing can fail. A gate
whose sole output is a false positive teaches you to ignore it, which is worse
than the gate being off and the reason being written down. Revisit when qlty's
Swift grammar changes.

I did not chase the parser bug further — it is third-party, and the
decision-relevant fact (the attribution is wrong by 1,172 lines) is
established.

## The hook runs it, because nothing else does

Origin is gitbay with no build configured, so these gates were only ever
evaluated by someone running them by hand. `.githooks/pre-push` now checks the
ratchet before the accessibility audit.

Two things I got wrong and had to fix before this worked:

- `qlty smells --quiet` **exits 0 even with findings**, so my first version
  (`if ! qlty smells`) would never have fired. The hook counts SARIF results
  instead.
- A plain SARIF count fails on day one: there are two pre-existing
  `similar-code` findings in `CloudSyncService` (a 15-line similar block). The
  hook counts only `qlty:file-complexity`; duplication stays reported, not
  gated.

## Verification

No Swift changed, so the test suite is untouched at 244 — I did not re-run it
for a config and hook change.

Layout: unified · split

.githooks/pre-push +52 −2
@@ -1,7 +1,7 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# 2#
3# Run the accessibility audit against the oldest supported simulator runtime 3# Run the complexity ratchet and the accessibility audit against the oldest
4# before pushing. 4# supported simulator runtime before pushing.
5# 5#
6# Enable once per clone: 6# Enable once per clone:
7# git config core.hooksPath .githooks 7# git config core.hooksPath .githooks
@@ -16,6 +16,11 @@
16# CI structurally cannot cover — and it is the one this machine can. Running 16# CI structurally cannot cover — and it is the one this machine can. Running
17# both here would just double the wait to re-check what CI already does. 17# both here would just double the wait to re-check what CI already does.
18# 18#
19# Why the hook runs qlty at all: nothing else does. This repository's origin is
20# gitbay, which has no build configured, so the smell gates in .qlty/qlty.toml
21# are only ever evaluated by someone running them. A ratchet nobody runs holds
22# nothing.
23#
19# Skip deliberately with: git push --no-verify 24# Skip deliberately with: git push --no-verify
20 25
21set -euo pipefail 26set -euo pipefail
@@ -51,6 +56,51 @@ if ! printf '%s' "$changed" | grep -qE '\.(swift|xcassets|xcodeproj)|\.pbxproj|x
51 exit 0 56 exit 0
52fi 57fi
53 58
59qlty=''
60for candidate in "$(command -v qlty || true)" "$HOME/.qlty/bin/qlty"; do
61 if [ -n "$candidate" ] && [ -x "$candidate" ]; then
62 qlty="$candidate"
63 break
64 fi
65done
66
67if [ -z "$qlty" ]; then
68 echo "pre-push: qlty not found, skipping the complexity ratchet"
69else
70 echo "pre-push: checking the complexity ratchet"
71
72 # Counted from SARIF rather than trusted to the exit code, which is 0 even
73 # with findings — `qlty smells --quiet` reports and does not fail. Only
74 # file-complexity is counted: duplication findings exist today
75 # (CloudSyncService has a 15-line similar block) and are reported, not gated.
76 over=$("$qlty" smells --all --sarif 2>/dev/null | python3 -c "
77import json, sys
78try:
79 document = json.load(sys.stdin)
80except Exception:
81 print('unknown')
82 raise SystemExit(0)
83print(sum(
84 1
85 for run in document.get('runs', [])
86 for result in run.get('results', [])
87 if result.get('ruleId') == 'qlty:file-complexity'
88))
89")
90
91 if [ "$over" = "unknown" ]; then
92 echo "pre-push: could not read qlty output, skipping the ratchet"
93 elif [ "$over" != "0" ]; then
94 echo
95 echo "pre-push: $over file(s) past the complexity threshold. Push aborted." >&2
96 echo " See './Scripts/../.qlty/qlty.toml'. Split the file, or lower" >&2
97 echo " the threshold deliberately — do not raise it to pass." >&2
98 echo " List them with 'qlty smells --all'." >&2
99 echo " Bypass with 'git push --no-verify'." >&2
100 exit 1
101 fi
102fi
103
54echo "pre-push: running accessibility audit on the floor runtime (~85s)" 104echo "pre-push: running accessibility audit on the floor runtime (~85s)"
55echo " skip with 'git push --no-verify'" 105echo " skip with 'git push --no-verify'"
56 106
.qlty/qlty.toml +25 −4
@@ -40,11 +40,29 @@ name = "trufflehog"
40[smells.return_statements] 40[smells.return_statements]
41enabled = false 41enabled = false
42 42
43# Function and file complexity are left to review rather than counted. 43# File complexity is a ratchet rather than a target. Measured 2026-10-25, the
44[smells.function_complexity] 44# ten worst files are ResultSectionViews 386, DomainViewModel 370, ContentView
45enabled = false 45# 306, CloudSyncService 198, DomainDataPortabilityService 146, WatchlistView
46 46# 146, AuditViews 128, DomainReportExporter 114, SettingsViews 112 and
47# WorkflowsView 107; twenty-two files exceed qlty's default. Splitting them is
48# not this finding's job, but letting them grow is avoidable, so the threshold
49# sits just above today's worst case and fails anything past it. Lower it when
50# a file is genuinely split, never raise it to make a commit pass.
47[smells.file_complexity] 51[smells.file_complexity]
52enabled = true
53
54# Function complexity stays off because qlty's Swift parser mis-attributes it
55# here, not because the metric is unwanted. It reports `existingShare`
56# (CloudSyncService:336, eight lines, seven statements) as complexity 184
57# spanning lines 336-1515 — the whole rest of the file. `fetchZoneChanges` in
58# the same file is measured correctly (31, lines 1049-1135), so the fault is
59# inconsistent rather than systematic.
60#
61# That leaves no usable threshold. Anything at or under 184 fails on the
62# artifact and nothing else; anything above it cannot fail on the one real
63# result. A gate whose only output is a false positive teaches you to ignore
64# it. Revisit when qlty's Swift grammar changes.
65[smells.function_complexity]
48enabled = false 66enabled = false
49 67
50# Exhaustive switch-over-enum lookup tables share shape but not content. 68# Exhaustive switch-over-enum lookup tables share shape but not content.
@@ -56,3 +74,6 @@ filter_patterns = [
56 "(switch_statement _)", 74 "(switch_statement _)",
57 "(function_declaration name: (simple_identifier) @_n (#match? @_n \"^(ownershipHistory|dnsHistory)$\"))", 75 "(function_declaration name: (simple_identifier) @_n (#match? @_n \"^(ownershipHistory|dnsHistory)$\"))",
58] 76]
77
78[language.swift.smells.file_complexity]
79threshold = 400