Commit 6197398ec1
Unsigned
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 | ||
| 21 | set -euo pipefail | 26 | set -euo pipefail |
| @@ -51,6 +56,51 @@ if ! printf '%s' "$changed" | grep -qE '\.(swift|xcassets|xcodeproj)|\.pbxproj|x | |||
| 51 | exit 0 | 56 | exit 0 |
| 52 | fi | 57 | fi |
| 53 | 58 | ||
| 59 | qlty='' | ||
| 60 | for 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 | ||
| 65 | done | ||
| 66 | |||
| 67 | if [ -z "$qlty" ]; then | ||
| 68 | echo "pre-push: qlty not found, skipping the complexity ratchet" | ||
| 69 | else | ||
| 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 " | ||
| 77 | import json, sys | ||
| 78 | try: | ||
| 79 | document = json.load(sys.stdin) | ||
| 80 | except Exception: | ||
| 81 | print('unknown') | ||
| 82 | raise SystemExit(0) | ||
| 83 | print(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 | ||
| 102 | fi | ||
| 103 | |||
| 54 | echo "pre-push: running accessibility audit on the floor runtime (~85s)" | 104 | echo "pre-push: running accessibility audit on the floor runtime (~85s)" |
| 55 | echo " skip with 'git push --no-verify'" | 105 | echo " 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] |
| 41 | enabled = false | 41 | enabled = 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 |
| 45 | enabled = 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] |
| 52 | enabled = 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] | ||
| 48 | enabled = false | 66 | enabled = 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] | ||
| 79 | threshold = 400 | ||