Public report — d2, published 6 Aug 2026.
Concrete security findings (CVE IDs, secret matches, dependency versions) are hidden in this version;
ask the repo owner for the full report.
548findings with an exact file:lineof 557 — the remainder are repo-wide signals (a dimension-level measurement, not a single line); open any file:line and verify
25/95dimensions across the health lenses44370 LoC — wide & deep
Executive summary
Read through the Preview lens: this repo is pre-1.0 / in development, so the colour bands are relaxed to what a preview needs — *green* means good enough for a preview, not yet production-stable. Code correctness and security stay near-strict even here; the score itself is absolute and comparable across repos.
terrastruct/d2 is sound in substance but carries real gaps (57%). It is not in crisis, but the issues below raise the cost of changing it — friction its consumers ultimately inherit.
It is strongest in Architecture (99%) — the structure is clean and changes stay contained.
The area that most needs attention is Readiness (49%) — releases are harder to depend on — versioning, release notes and dependency hygiene are thin, so consumers can't easily tell what changed or trust an upgrade. Code Health (53%) is the next concern — changes there are slower and more error-prone.
Leadership focus, highest impact first: SAST step to CI running what this repository's stack ships (Security & performance tooling); Stamp a version in your build/package manifest (e.g. csproj <Version> (Release Hygiene); Record significant decisions one document per decision (Architecture documentation).
For scale: Medium (~44,370 production lines); rebuilding it from scratch would take roughly ~0.5 person-years (~1–2 engineers). Approximate, ±~30%.
It builds on a genuinely strong Architecture foundation (99%); the priorities above are the highest-leverage way to bring the rest up to that level.
How the score is built — each lens's share of the headlineWidth is the lens's weight in the worst-heaviest fold (the weakest area pulls hardest); colour is that lens's own band. A lens fixes the score in proportion to its width.
A full-fidelity diff against the previous run's complete recorded findings — line-move tolerant: a finding that only shifted line counts as unchanged, only genuinely new titles/files surface here.
0.8× (at 57% quality) — the last 20% of quality is most of the work
Size & shape
Medium · effort split not classified (source measured from disk; the effort-tier breakdown is a C#-only syntax walk)
This codebase represents roughly ~0.5 person-years of build effort (about ~€78,000 to rebuild). Its weakest lens is Readiness at 49% — the part of that asset most exposed by the findings below.
How we model this: boilerplate at a scaffolding rate + logic × domain Standard (×1.0) — standard service × a 0.8× quality factor, at €60–95/h; indicative, ±~30% · size measured directly from source · effort from total production LoC as straight-line logic (the tier split is a C#-only syntax walk), a conservative lower bound. Indicative only — most sensitive to the hourly rate and the domain tier (both tunable in config).
Top priorities
The highest-leverage moves; the full ranked list is in the Roadmap below.
1
Add a SAST step to CI running what this repository's stack ships: gosec / govulncheck (or golangci-lint) — or `semgrep --config=auto`, which runs on any language — so a security regression fails the build instead of landing.
Stamp a version in your build/package manifest (e.g. csproj <Version>, package.json, pyproject.toml, Cargo.toml, or a VERSION file) or tag releases with semver so builds and releases are traceable.
Record significant decisions one document per decision — dated, stating the context, the decision and its consequences — and keep them together wherever your design docs already live (a conventional `docs/adr/` tree with `NNNN-title.md` names is the most discoverable form).
The top-ranked fix costs roughly 3–10 engineer-days once. Not doing it costs about 1.6–9.6 engineer-days every year, paid as drag on the ~6,785 lines this team changes annually — a bill that arrives whether or not anyone books it. On those figures the fix breaks even in roughly 4–75 months and is free after that. Method, stated so this is not read as a quotation: debt from the ranked task's effort band; interest = annual changed lines (measured, annualised from the 90-day window) ÷ an ASSUMED 150–400 lines per engineer-day × the 9–21% drag implied by the code-quality signals; breaking point = debt ÷ annual interest. A modelled planning range built from measured inputs and one named assumption — not a quotation, a valuation, or a certified figure.
Evidence: D15 churn: 1,673 line(s) changed over a 90-day window ⇒ ~6,785/year · D1/D2/D4 code quality: averaging 4.2/10 ⇒ a 9–21% drag on each change · top-ranked remediation: Medium effort ⇒ about 3–10 engineer-day(s)
→ Do the top-ranked fix now if this code will still be yours in 75 months.
Value concentrated against a weak lens · Medium · Value at risk
This is a Medium asset (~0.5 person-years to rebuild), and its weakest lens is Readiness at 49%. The operational and business risk on an asset this size concentrates there — that's where remediation buys the most protection.
→ Direct remediation budget at Readiness first — highest risk-reduction per euro on an asset this size.
Highest-leverage move · Medium · Leverage
Of everything flagged, the best return on effort is: Add a SAST step to CI running what this repository's stack ships: gosec / govulncheck (or golangci-lint) — or `semgrep --config=auto`, which runs on any language — so a security regression fails the build instead of landing. The rest can wait behind it.
Evidence: priority ranking: top of 5 ranked by impact/effort
→ Add a SAST step to CI running what this repository's stack ships: gosec / govulncheck (or golangci-lint) — or `semgrep --config=auto`, which runs on any language — so a security regression fails the build instead of landing.
A velocity tax on every change · Medium · Economics
The code-quality signals (complexity, duplication, cohesion) average 4.2/10, which acts as a tax on every change in the weaker areas: modifications there plausibly cost on the order of 9–21% more than in clean code, and the tax compounds as the codebase grows. (A modelled estimate, not a measured fact.)
Evidence: D1/D2/D4 code quality: averaging 4.2/10 across the code-quality signals actually measured
→ Pay it down where churn is highest — the hotspots — not everywhere; that's where the tax is actually paid.
Architecture — module dependency matrix
65 modules, 95 dependencies — 1 dependency cycle, shown as the red cell(s) above the diagonal. Rows and columns are the same modules, ordered so that a module only depends on ones above it. A cell means the row depends on the column, and its number is how many type pairs create that dependency. Read one thing: is anything above the diagonal? A mark there is a dependency cycle. (A cycle is all this shows — an unusual but cycle-free dependency sits below the diagonal like any other.)
At a glance — Code Health · 53% · Adequate · gated by D1, D2
Findings mapped to OWASP categories; the specific CVEs/secrets are in the Security dimension cards below and findings.md (redacted only on the public version of this report).
OWASP category
Findings
Severity
A03:2021 — Injection
17
High / Critical
A05:2021 — Security Misconfiguration
11
High / Critical
A06:2021 — Vulnerable & Outdated Components
6
High / Critical
Roadmap
First, integrate a security scanning step into the CI pipeline to fail the build on regressions, and resolve the existing high-priority static analysis findings. Next, enforce release hygiene by stamping a version in the build manifest or tagging releases with semver to ensure traceability. Then, document significant architectural decisions in a dedicated ADR format to capture context and consequences. Finally, update the root README with a testing section to clarify how to run the test suite.
Ranked by impact ÷ effort. "Helps" is the estimated gain on the 0–100 health score.
Do this
Helps
Effort
Dimension
Add a SAST step to CI running what this repository's stack ships: gosec / govulncheck (or golangci-lint) — or `semgrep --config=auto`, which runs on any language — so a security regression fails the build instead of landing.
Stamp a version in your build/package manifest (e.g. csproj <Version>, package.json, pyproject.toml, Cargo.toml, or a VERSION file) or tag releases with semver so builds and releases are traceable.
Record significant decisions one document per decision — dated, stating the context, the decision and its consequences — and keep them together wherever your design docs already live (a conventional `docs/adr/` tree with `NNNN-title.md` names is the most discoverable form).
Watchdog is a deep, periodic assessment — run each sprint, monthly, or quarterly, taking the time to go wider and deeper than a quick check and surfacing in one coherent report what you'd otherwise piece together from a dozen separate tools. It scores deterministically: the same commit yields the same score, every run. 23 of 25 evaluated dimensions are computed purely by tools and static analysis (confidence 1.0); 2 documentation/naming judgement(s) are LLM-assisted and labelled advisory. Overall confidence is 0.6 — the weighted average across measured dimensions; it falls as more of the score leans on LLM-assisted judgement and rises when it's fully tool-backed.
Every figure here is one of three kinds, and we label which: ✓ Measured — a deterministic fact (LoC, complexity, coverage); ~ Modeled — an estimate from a stated model (cost, effort, value-at-risk), always a range with its assumptions, never a precise fact; ◐ Advisory — an LLM prose judgement. We never present a modelled estimate as if it were measured. Perfect or absent scores carry their provenance too (ADR-0011): ✓ Tool-verified means the property itself was measured across the surface; ○ Nothing flagged means the probes came back clean — a claim bounded by what a repository can show; ⊘ Not evidenced means a working control (a tested restore, an automated rollback) showed no positive evidence — absence of evidence is not evidence of a control, so it's excluded from the score rather than awarded a spurious 10; ◐ Sampled · advisory marks an LLM verdict over a bounded sample — advisory, never a deterministic measurement.
What we checked — 25 dimensions across the health lenses
Each chip is a dimension scored from real signals across architecture, testing, dependencies, security & compliance, documentation, git-history and code quality — in one coherent pass. A surface report typically covers a handful.
How to trust any code-health report — three questions
Can you open the finding? Real findings cite a repo-relative file and line you can open at the cited line — never an absolute scratch path. Here, 548 of 557 do; the remainder are repo-wide signals — a dimension-level measurement, not a single line. (Every path in this report is repo-relative by construction: paths are normalized at the producer and the report is rejected if any rooted path leaks through.)
Is there a tool behind the number? Every score below names the method that produced it — Roslyn, git, a scanner, or (for a handful of documentation/naming dimensions) an LLM labelled sampled · advisory — not a narrative.
Does re-running give the same result? Run it again on the same commit and the score — and this report, byte for byte — is identical. A report whose numbers move between runs is describing the run, not the code.
This report answers yes to all three. That's the bar to hold any assessment to.
Tools & methods
The actual versions used this run (captured at analysis time) — re-run on the same commit for the identical score.
Method
Backs
Version
Evaluator
Roslyn static analysis
Complexity, cohesion, coupling, dead code, API surface, layering
What ran differently this time — a tool absent, degraded, or that fell back to an estimate. Named openly, not folded silently into the scores. A degraded run also records its exact cause in diagnostics.md.
D30 Dependency Vulnerabilities — scanner not present in this environment — The backing tool was not installed where this scan ran, so this dimension was not scored. Install the tool (or run in the hosted environment, where it is always present) for a graded result.
Repo exclusion declarations: 26 pattern(s) declared (.gitattributes linguist-generated/vendored, .editorconfig generated_code) excluded 0 source file(s) from code-quality scoring. Declarations are the repo's own visible statement that a tree is machine-written or vendored — auditable in any diff, honored by GitHub the same way.
Limitations & what we did not check
Watchdog assesses the repository exactly as committed, and only the repository. By design it does not reach outside the source tree: the live cloud account, the running CI/CD pipeline, the host's branch-protection and approval rules, the production configuration, or a restore actually exercised against a backup are all out of scope. That boundary is a feature, not a gap — a repo-relative, deterministic scan re-runs identically on any commit and every finding opens at a real file and line, where a live audit can neither be reproduced nor traced. The visible consequence is that controls which leave no in-repo evidence are reported as "not evidenced" and excluded from the score rather than awarded a number a static scan cannot justify.
Per-dimension blind spots
For each dimension that was measured, what a static, repo-only scan structurally cannot see — the honest edge of the measurement, not a failure of it.
D1 Cyclomatic Complexity: Cyclomatic complexity counts branches statically — it cannot tell an essential decision tree from accidental tangle, nor see complexity that lives in data or configuration (large switch-case token tables, DSL lexers/parsers, data-as-code rule tables) rather than control flow: a tokenizer's many single-character cases read as high complexity though each branch is trivial.
D2 Cognitive Complexity: Cognitive-complexity heuristics approximate how hard code is to follow; genuine domain difficulty and well-named intent that eases reading are not captured.
D3 God Classes: "God class" is sized by members and responsibilities visible in the type — a deliberately broad facade over a coherent subsystem can read the same as an accidental grab-bag. For front-end JS the file-length check is cohesion-aware (a single-responsibility module — one class/IIFE — earns a 3× threshold), but cohesion is approximated from top-level declarations, not true dependency structure.
D4 Code Duplication: Duplication is token-similarity (jscpd) — it finds copy-paste, not semantic duplication expressed differently. Committed machine-written code (scaffolded migrations, designer/codegen output, protobuf/OpenAPI stubs, model snapshots) is EXCLUDED — its repetition is the tool's, not the team's — so the score reflects hand-written duplication only.
D13 Secret Scanning: Secret detection is signature- and entropy-based on the current tree — a secret that does not match a known pattern, or one already rotated, will not be flagged (a clean scan is "nothing matched", not "no secrets exist").
D15 Churn × Complexity Hotspots: Churn hotspots come from git history — a freshly imported or squashed repository has no churn signal, and recent rewrites can mask a historically risky file.
D16 Bus Factor: Bus-factor is a time-decayed model of commit attribution (who has recently, repeatedly worked a file), not comprehension — pairing, review and reading-without-committing spread knowledge it can't see; bot commits and shared accounts still distort it.
D19 Documentation Quality: Documentation quality is judged by an LLM over a bounded sample of docs — it reads what is written, not whether the docs match the running system, and it is advisory, not a measurement.
D21 Naming Consistency: Naming quality is an LLM judgement over a bounded sample — it assesses clarity/consistency of the names it sees, not domain-correctness, and is advisory.
D28 Secrets (history): Secret-history scanning sweeps the git log for known patterns — a secret that predates the available history, or never matched a signature, is not found (clean means "nothing matched in the history we can see").
D29 Static Analysis (SAST): SAST findings are pattern-based (semgrep) — it finds classes of bug it has rules for; logic flaws, auth/authorization gaps and issues needing runtime context are out of reach (and clean means "no rule matched").
D31 IaC & Container Security: IaC scanning checks Dockerfiles/Terraform/Kubernetes against best-practice rules — it cannot see the live cloud account, runtime configuration, or drift between the committed config and what is actually deployed.
D33 JS/npm Dependency Vulnerabilities: JS/npm CVE matching reads package manifests and lockfiles — risk from how a dependency is used, and advisories not yet published, fall outside this scan.
D34 Knowledge Freshness: Freshness is decayed commit RECENCY, not comprehension — code read often but rarely committed reads as orphaned, and stable code that genuinely needs no changes is penalised the same as forgotten code; bot/squash commits distort it like the bus factor.
D35 Change Coupling: Change coupling is co-change in COMMITS — files split across separate commits, or coupled only through a shared config/build step, read as uncoupled, and a sweeping commit (rename/format) is excluded so it doesn't couple everything. It shows that files change together, not WHY: a high coupling can be a healthy cohesive pair as readily as a hidden leak.
M4 Documentation accuracy: Onboarding quality is an LLM read of the docs/setup present — it cannot run the onboarding or measure how long a real new joiner takes; the verdict is sampled and advisory.
P4 Deployment & Rollback: Approval/branch-protection rules live in repository settings the scan cannot see — only their in-repo evidence (config files, workflows) is checked, so a control enforced purely in the host's settings reads as "not evidenced".
P6 Release Hygiene: Rollback/observability controls are inferred from repo artefacts (pipelines, dashboards-as-code) — controls configured in external tooling, with no in-repo trace, cannot be credited.
The LLM boundary
LLM-set scores this run (3): D19, D21, M4 (model: Local LLM). For these, a model reads a bounded sample and sets the numeric score (documentation, ADR quality, naming, comment value, onboarding) — D25 sets the ADR-conformance fraction over sampled code, D22 judges API accuracy over a sample. These are sampled and advisory by design: they vary at the margins between runs and are never a deterministic measurement. Every other score in this report is tool-computed at confidence 1.0.
What it measures: How tangled the control flow is — methods with many branches are hard to test and change.
Method: Cyclomatic complexity per method (1 + decision points), computed exhaustively across production source; test projects separated by convention. Deterministic.
144 method(s) exceeded the cyclomatic complexity threshold of 15; the worst was d2oracle._set at 182. A further 9 method(s) were over the threshold but excluded as flat dispatchers (a long switch/match over independent cases: many branches, almost no nesting), the largest being label.FromString at 37 — they are counted neither in the figure above nor in this dimension's score.
+ 139 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 1 d2oracle._set (cyclomatic 182) finding(s) in Cyclomatic Complexity — start with edit.go. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 d2oracle.move (cyclomatic 121) finding(s) in Cyclomatic Complexity — start with edit.go. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 d2svg.drawShape (cyclomatic 107) finding(s) in Cyclomatic Complexity — start with d2svg.go. — One of this dimension's main actionable groups (1 warning-level).
Enforce Cyclomatic Complexity in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
Detailed fixes: d1_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How hard the code is for a person to follow, beyond raw branching.
Method: Cognitive complexity per method (Sonar-style nesting-penalized score), computed exhaustively over production code, excluding test projects. Deterministic.
+ 218 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 1 d2oracle._set (cognitive 455) finding(s) in Cognitive Complexity — start with edit.go. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 d2oracle.move (cognitive 356) finding(s) in Cognitive Complexity — start with edit.go. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 d2dagrelayout.shiftReachableDown (cognitive 279) finding(s) in Cognitive Complexity — start with layout.go. — One of this dimension's main actionable groups (1 warning-level).
Enforce Cognitive Complexity in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
Detailed fixes: d2_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D3 · God Classes8.4 / 10Strong✓ Tool-verified
What it measures: Over-large classes that try to do too much ("god classes").
Method: God-class detection by line and method-count thresholds per logical type (partial classes unified), filtered for generated code and registration/contract false positives. Deterministic.
Resolve the 15 FileTooLong finding(s) in God Classes — start with layout.go (3), compile.go (2), d2svg.go. — One of this dimension's main actionable groups (15 warning-level).
Resolve the 4 TooManyMethods finding(s) in God Classes — start with d2graph.go, d2ir.go, parse.go. — One of this dimension's main actionable groups (4 warning-level).
Enforce God Classes in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Prevented — provenance only; does not change the score.
Detailed fixes: d3_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Copy-pasted code that should be shared instead.
Method: Code duplication via token-stream sliding windows with type-aware normalization (locals masked, type names preserved), density-scored per KLoC of production code. Deterministic.
+ 17 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 18 Duplicated block (9 lines × 2) finding(s) in Code Duplication — start with d2ir.go (3), layout.go (2), edit.go (2). — One of this dimension's main actionable groups (18 warning-level).
Resolve the 13 Duplicated block (10 lines × 2) finding(s) in Code Duplication — start with d2ir.go (2), parse.go (2), d2svg.go (2). — One of this dimension's main actionable groups (13 warning-level).
Resolve the 13 Duplicated block (8 lines × 2) finding(s) in Code Duplication — start with compile.go (2), layout.go (2), sketch.go (2). — One of this dimension's main actionable groups (13 warning-level).
Enforce Code Duplication in CI to reach Verified (currently Documented). — Hardens enforcement from Documented toward Verified — provenance only; does not change the score.
Detailed fixes: d4_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any secrets (keys, tokens, passwords) have leaked into the code.
Method: In-process native secret scanner (entropy plus signature patterns) across all tracked files; no external tool. A clean result is a measured 10, not no-data zero. Deterministic.
What it measures: Files that change often and are also complex — the riskiest hotspots.
Method: Per production file churn times cyclomatic complexity over a rolling window, computed from git and Roslyn/JS/Razor analysis. Exhaustive, deterministic per commit date.
Detailed fixes: d15_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D16 · Bus Factor7.3 / 10Strong✓ Tool-verified
What it measures: Whether knowledge is concentrated in too few people (the "bus factor").
Method: Living knowledge per author via time-decayed commit attribution (6-month half-life, focus weighting) across largest source files. Deterministic, avoids blame's mechanical-refactor false positives.
22 source file(s) have their living knowledge concentrated in one author (≥90% of recent, decayed contribution). The largest is d2oracle/edit.go.
Off-boarding risk: anonymized user #1
Further sole-owners (lower concentration)
What to do
Resolve the 1 Off-boarding risk finding(s) in Bus Factor. — One of this dimension's main actionable groups (1 recommendation-level).
Resolve the 1 Further sole-owners (lower concentration) finding(s) in Bus Factor. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d16_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the project's documentation is clear, complete, and useful.
Method: Judged by language model at low temperature (0.0-0.1) on a deterministic doc sample (READMEs plus first 25 architecture docs), with two-pass stability filtering. Advisory, sampled.
D2's documentation is clear and complete for a tool of this kind: an extensive README with a table of contents listing every major topic (What does D2 look like?, Quickstart, Install, D2 as a library, Themes, Fonts, Export file types, Language tooling, Plugins, Comparison, Contributing, License, Related), plus focused markdown docs for themes, fonts, release scripts, and the full contributing guide. The README also links to cheat sheets, CI workflows, a playground, and an install.sh cheat sheet; the architecture/design docs are well integrated into the narrative.
The library examples directory is referenced but only one example (1-d2lib) is shown with no links to the other two (d2oracle, lowlevel).docs/examples/lib/README.md
✓ On the Gold path — maintain.
Detailed fixes: d19_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether names — types, methods, variables — are clear and consistent.
Method: Judged by language model at low temperature (0.0-0.1) on a deterministic random symbol sample (fixed size, not exhaustive), with disclosed confidence band. Advisory, sampled.
What it measures: Whether any secrets were ever committed — scanned across the full git history, not just now.
Method: Git-history secret scan via gitleaks detect over full history in an isolated checkout; each match flagged High. Exhaustive; degrades cleanly when tool absent.
What it measures: Real static-analysis (SAST) findings — likely security bugs in the code, any language.
Method: Polyglot static analysis via semgrep across the repo using the pinned, image-baked p/security-audit + p/owasp-top-ten rulesets (no scan-time registry fetch); severity rules (ERROR/WARNING/INFO) map to a full-band severity-weighted score. Exhaustive, deterministic; degrades on parse failure.
Coverage: semgrep pattern rules over all files — exhaustive for the rule set, blind to classes of bug without a rule (clean = no rule matched).
High: github-actions-mutable-action-tag · ×13.github/workflows/ci.yml:14detected by semgrep finding
Medium: math-random-used · ×4d2chaos/d2chaos.go:5detected by semgrep finding
What to do
Resolve the 13 High finding(s) in Static Analysis (SAST) — start with ci.yml (5), daily.yml (3), npm-stage.yml (3). — One of this dimension's main actionable groups (13 issue-level).
Resolve the 4 Medium finding(s) in Static Analysis (SAST) — start with d2chaos.go, template.html, gradient.go. — One of this dimension's main actionable groups (4 warning-level).
Detailed fixes: d29_recommendation.md · top locations in Appendix A, every location in findings.md.
High IaC: DS-0029 · ×4ci/release/docker/Dockerfiledetected by trivy finding
Medium IaC: DS-0001 · ×5ci/release/docker/Dockerfiledetected by trivy finding
Low IaC: DS-0005 · ×2ci/release/docker/Dockerfiledetected by trivy finding
What to do
Resolve the 4 High IaC finding(s) in IaC & Container Security — start with Dockerfile (4). — One of this dimension's main actionable groups (4 issue-level).
Resolve the 5 Medium IaC finding(s) in IaC & Container Security — start with Dockerfile (5). — One of this dimension's main actionable groups (5 warning-level).
Resolve the 2 Low IaC finding(s) in IaC & Container Security — start with Dockerfile (2). — One of this dimension's main actionable groups (2 recommendation-level).
Detailed fixes: d31_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether anyone still has living knowledge of each file, or it has been orphaned — last understood long ago by someone now gone quiet. The sibling of the bus factor: D16 asks who owns it, D34 asks whether anyone still knows it.
Method: File orphaning as total living-knowledge decay below one focused-commit's worth within a year, computed per-file from the D16 decay model. Exhaustive, deterministic over fixed history.
4 of 82 significant source file(s) are orphaned — their living knowledge has decayed to nothing, so no one currently understands them. The largest is lib/font/subsetFont.go.
Orphaned knowledgelib/font/subsetFont.go
Further orphaned files (smaller)
✓ On the Gold path — maintain.
Detailed fixes: d34_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether files that change together actually belong together — pairs that repeatedly co-change in git history despite having no explicit code dependency, surfacing the hidden/logical coupling (and boundaries in the wrong place) a static scan can't see.
Method: Pairwise co-occurrence over the per-commit file sets in git history (production source only — tests and generated dropped): Degree-of-Coupling = shared ÷ min individual revisions, reported above noise floors (each file ≥10 revisions, ≥5 shared commits, ≥50% strength); sweeping commits excluded. Deterministic over fixed history.
Coverage: Population: PRODUCTION source files only — test and generated files are dropped before pairing, so a class co-changing with its own test (trivially ~100%) can't drown the real production↔production coupling. Pairs ranked by Degree-of-Coupling; coupling through a build step, config, or non-source file isn't seen.
What it measures: Whether the build pipeline provides supply-chain integrity — generated provenance/attestation, signed artifacts (cosign/sigstore), an SBOM, and pinned build actions. Presence of the configuration, not a runtime guarantee.
Method: Supply-chain provenance/signing read deterministically from CI/build config (.github/workflows, .gitlab-ci.yml, azure-pipelines, Jenkinsfile, .circleci) + the release surface: four signals — generated provenance/attestation (SLSA/in-toto/actions-attest), artifact signing (cosign/sigstore/gitsign), an SBOM (syft/sbom-action/*.spdx.json/*.cdx.json), and SHA-pinned build actions — scored 10·present/denom. NotApplicable without a build pipeline. Detects configuration presence, not runtime enforcement.
Resolve the 1 Unpinned build actions finding(s) in Supply-chain Provenance & Signing. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 No SBOM finding(s) in Supply-chain Provenance & Signing. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d36_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether dependencies have known published vulnerabilities (CVEs) per the OSV database — read natively from whatever lockfile the repository ships (Cargo, npm, Go, Python, Maven, RubyGems, …). D33 and D30 add ecosystem-specific scanners on top for npm and .NET.
Method: Multi-ecosystem dependency-CVE scan via osv-scanner --recursive (queries the osv.dev database + parses lockfiles natively across ecosystems: npm package-lock/yarn/pnpm/bun, Go go.mod, Rust Cargo.lock, Maven/Gradle pom.xml/gradle.lockfile, PyPI requirements.txt/poetry.lock/Pipfile.lock, Composer composer.lock, RubyGems Gemfile.lock, Hex mix.lock, pub pubspec.lock, Swift Package.resolved); severity tally (Critical/High/Medium/Low) to 0-10 tight normalizer (8.0). NotApplicable only when the repo declares no supported non-.NET dependency lockfile (a NuGet-only repo stays NotApplicable — .NET CVEs are D30's domain); coverage needs a resolved lockfile. Additive to D33 (trivy fs); exhaustive + deterministic, DB kept fresh.
High CVE: [GHSA redacted]go.moddetected by osv-scanner finding
Medium CVE: GO-2026-5320 · ×5go.moddetected by osv-scanner finding
What to do
Resolve the 1 High CVE finding(s) in OSV Dependency Vulnerabilities — start with go.mod. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 5 Medium CVE finding(s) in OSV Dependency Vulnerabilities — start with go.mod (5). — One of this dimension's main actionable groups (5 warning-level).
Detailed fixes: d38_recommendation.md · top locations in Appendix A, every location in findings.md.
Maturity · Maturity — Whether the repo and its projects have a README, and whether it's substantive and current.
Method: Filesystem scan: README presence, word count, and headings for depth; git history for staleness. Exhaustive across root and project dirs, deterministic.
What to do
Add a 'Testing' section to the root README — how to run the test suite.
Add an 'Architecture' / 'How it works' section to the root README — the high-level shape.
Maturity · Maturity — Whether key decisions (ADRs) and the high-level shape (C4/diagrams) are written down.
Method: Filesystem scan: ADR folder/naming conventions or content, plus Mermaid/PlantUML/C4/architecture.md discovery. Exhaustive, deterministic.
No Architecture Decision Records found — no conventional ADR directory, no `NNNN-title.md` documents and nothing ADR-shaped by content. Design rationale recorded elsewhere (a design-notes tree, a mailing list, pull-request discussion) is not visible to this check and is not re-findable per decision, so a future maintainer cannot ask why one choice was made and get an answer.
What to do
Record significant decisions one document per decision — dated, stating the context, the decision and its consequences — and keep them together wherever your design docs already live (a conventional `docs/adr/` tree with `NNNN-title.md` names is the most discoverable form).
Maturity · Maturity — Whether the README actually describes the code that exists (LLM-judged, advisory).
Method: Judged by language model at low temperature: README accuracy versus actual projects, within a disclosed tolerance. Advisory, not a measured number.
Readiness · Readiness — Whether SAST, secret/dependency scanning and performance benchmarking are wired in (presence, not runtime).
Method: Filesystem scan: SAST configuration, dependency-update automation, secret scanning, and a benchmark harness or benchmark step — in this repository's own ecosystem. Exhaustive, deterministic.
No static application security testing detected. For this repository's stack, add gosec / govulncheck (or golangci-lint) (or `semgrep --config=auto`, which runs on any language) as a CI step.
What to do
Add a SAST step to CI running what this repository's stack ships: gosec / govulncheck (or golangci-lint) — or `semgrep --config=auto`, which runs on any language — so a security regression fails the build instead of landing.
Enable Dependabot/Renovate or a dependency-review gate.
Add gitleaks/trufflehog in CI to block PRs that introduce committed secrets.
Readiness · Readiness — Whether releases are automated and safely reversible (probes, rolling updates, approval gates) — from manifests/pipeline files, not the live environment.
Method: Filesystem scan: deployment manifests/IaC (K8s YAML, Helm, Terraform) for rolling updates, probes, approval gates, migration hooks. Exhaustive, deterministic.
Readiness · Readiness — Whether releases are traceable — a maintained changelog and explicit version stamping.
Method: Filesystem scan: changelog file presence and version tags in csproj or git tags. Exhaustive, deterministic.
What to do
Stamp a version in your build/package manifest (e.g. csproj <Version>, package.json, pyproject.toml, Cargo.toml, or a VERSION file) or tag releases with semver so builds and releases are traceable.
Do you agree with this assessment?
Reference — by lens
The score is the rank-weighted fold of these lenses (worst-heaviest), each including its meta-dimensions; a lens with a Critical contributor is capped at Fair (its band reads "gated by …") and is never the strongest area however high its average.
Capped at Fair by a Critical contributor — resolve it before relying on this lens.
Not included — 70 check(s) not relevant to this codebase
These checks had nothing to measure here (no tests, no git history, the codebase is small, or the architecture style doesn't apply), so they're omitted above rather than scored low.
AC1 Text alternatives — Frontend below the scale floor (18 DOM element(s) < 25) — too little surface to assess accessibility.
AC2 Forms & labels — Frontend below the scale floor (18 DOM element(s) < 25) — too little surface to assess accessibility.
AC3 Page structure — Frontend below the scale floor (18 DOM element(s) < 25) — too little surface to assess accessibility.
AC4 Keyboard semantics — Frontend below the scale floor (18 DOM element(s) < 25) — too little surface to assess accessibility.
AC5 ARIA correctness — Frontend below the scale floor (18 DOM element(s) < 25) — too little surface to assess accessibility.
AC6 Visual & motion safety — Frontend below the scale floor (18 DOM element(s) < 25) — too little surface to assess accessibility.
AC7 A11y enforcement — Frontend below the scale floor (18 DOM element(s) < 25) — too little surface to assess accessibility.
AX1 Captive dependencies — no DI registrations detected
AX10 Code composition — not assessed — code composition is computed by ROLE over a document set that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX2 Stateful singletons — no singleton implementations detected
AX3 Project dependency cycles — not assessed — project cycles and dependency direction are computed over a project-reference graph that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX4 Dependency direction — not assessed — project cycles and dependency direction are computed over a project-reference graph that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX5 Architecture & structure — not assessed — architecture style/structure is computed from a project graph (projects, types, module namespaces) that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX6 Interface segregation — not assessed — interface segregation is computed over a type surface that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX7 Slice cohesion — not applicable — not a vertical-slice architecture
AX8 Test isolation — not assessed — test isolation is computed from a project graph (which projects are test projects, and what they reference) that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX9 CQS / query purity — no CQRS query handlers detected — query purity is not applicable to this codebase
AXB2 Runtime readiness — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
C1 Data Protection — Not assessed: these personal data controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks personal data controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C2 Access Controls — Not assessed: these authorization controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks authorization controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C3 Audit Trail — Not assessed: these audit controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks audit controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C4 Data Retention — Not assessed: these retention controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks retention controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C5 Data-Subject Rights — Not assessed: these data-subject rights controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks data-subject rights controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
D10 Test Quality — ~31131 lines of test source are present (.go, .js) but the test-quality collector reads C# only, so skipped/assertion-free tests couldn't be counted. Not scored — this is a gap in the analyzer, not a finding about this repository.
D11 Test Reliability — Test reliability not included
D12 Dependency Hygiene — Dependency hygiene not measured — dependency manifest found but not parsed for hygiene
D14 License Compliance — Not scored — this repository's package manifest is not parsed for licence data yet. A gap in the analyzer's language coverage, NOT a finding that the repository's licenses are compliant (a Go module (go.mod/go.sum)), which this pass does not parse yet — so this dimension asserts nothing about this repository's licensing in either direction.
D17 Explicit Debt — explicit-debt markers are read through a C# workspace today, so they were not read for this repository's language — this asserts nothing about how many markers the code carries. Not scored — this is a gap in the analyzer, not a finding about this repository
D18 Solution Shape — D18 scores the shape of a .NET solution; this repository has no .NET solution or project files, so the dimension does not apply.
D20 ADR Quality — N/A — ADRs are expected on deployable products with a user-facing host, not consumed libraries; no ADR log is required here.
D22 Internal API Consistency — No exposed public API
D23 Boundary Type-Coupling — Production source is present (.go) but bounded contexts are resolved over the C#/VB project set, which exposed none, so context scope could not be assessed. Not scored — this is a gap in the analyzer, not a verdict about this repository. Declaring the codebase's bounded contexts (≥2) would let cross-boundary type coupling be assessed — see the recommendation on this dimension for where. Declare them in `.codehealth/config.yaml` at the repository root (create it if absent), mapping each context name to the module-path or namespace prefixes that belong to it — e.g. `architecture:` → `contexts:` → `Billing: ["src/billing", "Acme.Billing"]`, `Catalog: ["src/catalog", "Acme.Catalog"]`.
D24 Comment Value — No inline comments to assess — comment value is not applicable here.
D25 ADR Conformance — no ADRs to check
D26 Project Cohesion — Project cohesion is assessed over the .NET project set; this target exposed no projects, so project size and spread could not be assessed. Not scored — this is a gap in the analyzer's reach, not a verdict about this repository.
D27 Navigability — No calls could be sampled, so navigability was not assessed — tracing effort is measured over resolved call sites and this target exposed none. Not scored — this is a gap in the analyzer's reach, not a verdict about this repository.
D30 Dependency Vulnerabilities — Not scored — no dependency manifest in a supported ecosystem was read for this repository. A gap in the analyzer's language coverage, NOT a finding that the repository is free of vulnerable dependencies (a Go module (go.mod/go.sum) — not scanned yet) — where an OSV-supported manifest exists, dependency vulnerabilities for this repository are reported under D38 instead.
D32 Data Compliance (PII/GDPR) — No PII/GDPR-handling patterns detected (p/gdpr ruleset) — no data-compliance surface to assess.
D37 Vulnerability-disclosure Policy — No vulnerability-disclosure policy file found (SECURITY.md/.markdown/.rst/.txt at root or under .github/.forgejo/.gitea/docs, .well-known/security.txt). A coordinated-disclosure policy may live off-repo, so this is not evidenced rather than failed.
D39 IL Efficiency — D39 measures the IL emitted by a .NET build; this repository has no .NET solution or project files, so the dimension does not apply.
D40 Network Egress Confinement — No Kubernetes/orchestration workloads found in the repository manifests; network egress policy is a cluster-native control that may live at the platform/firewall layer, so there is nothing to assess here.
D41 Kernel & Syscall Confinement — No Kubernetes/orchestration workloads found in the repository manifests; seccomp/AppArmor/SELinux confinement is a workload-level control, so there is nothing to assess here.
D42 Runtime Threat Enforcement — No Kubernetes/orchestration workloads found in the repository manifests; runtime threat-detection and admission-control policy are cluster-level controls, so there is nothing to assess here.
D5 Coupling — Inter-project coupling could not be assessed — no analyzable project graph was found for this repository. Not scored: a gap in the analyzer's reach, not a verdict about this repository. (Coupling here is Martin afferent/efferent/instability plus reference cycles across a project-reference graph, read today from .NET project files; other ecosystems' module graphs are not read yet.)
D6 Cohesion (LCOM4) — Cohesion (LCOM4) is measured over a C#/VB class graph, and this repository's production source is mostly .go, which this pass does not read, so cohesion was not assessed for this repository. Not scored — this is a gap in the analyzer, not a finding about this repository.
D7 Architectural Integrity — no checkable ADRs, and no project-reference graph for the cycle pass to read — so this dimension makes no claim about dependency cycles in either direction (where this repository's language has an import-cycle lens, cycles are reported there). Architectural integrity not assessed
D8 Code Coverage — Coverage not included — suite not readable by the collector
D9 Test Distribution — Test source is present (.go, .js) but the test-pyramid classifier reads C# only, so its unit/integration/BDD/E2E split couldn't be counted. Not scored — this is a gap in the analyzer, not a finding about this repository.
DM1 Domain Modelling — applicable but not scored (1 of 2 signals for this style — below the bar we score at): 2 value object(s)
ED1 Event-Driven — not scored — this repository shows none of the 3 signals this check looks for
ED5 Idempotency — no mutating command handlers or message consumers detected — idempotency check not applicable
ES1 Event Sourcing — not scored — this repository shows none of the 3 signals this check looks for
GD1 Unfinished & placeholder code — no source files
IC1 Incompleteness & stubs — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
P12 CI test-gate honesty — Reported, not scored — this card publishes what the CI gate does with the test inventory rather than grading it. The findings above are its output.
P2 Observability — Observability was not assessed: this check reads a source model that does not carry this repository's product — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of a logging idiom this check recognises is NOT evidence that this repo lacks structured logging (it may log through its own ecosystem's logger). This is a gap in the analyzer, not a finding about this repository.
P5 DR & Backup — not evidenced — repo shows no backup/RTO/RPO controls; absence of evidence is not evidence of a working control
P7 Outbound HTTP resilience — not measured — the application kind could not be determined for this repo
P8 Schema migrations — not assessed — schema-migration practice is read from a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
P9 Domain vs controller coverage — no coverage report found on disk — produce a coverage report in a standard format (`go test -coverprofile=coverage.out ./...`) into the repo working tree before the scan — a CI step is the usual place, since the artefact is commonly gitignored, or wire coverage collection into CI, to enable this cross-layer check
PF1 Benchmark discipline — Performance was not assessed: this lens reads a source model that was not loaded for this repository, because the repository is written in a language this lens does not yet model or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository — in particular it is NOT a statement that this repo is unpackaged or performance-careless.
PF2 Allocation hygiene — Performance was not assessed: this lens reads a source model that was not loaded for this repository, because the repository is written in a language this lens does not yet model or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository — in particular it is NOT a statement that this repo is unpackaged or performance-careless.
PF3 Async & latency hygiene — Performance was not assessed: this lens reads a source model that was not loaded for this repository, because the repository is written in a language this lens does not yet model or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository — in particular it is NOT a statement that this repo is unpackaged or performance-careless.
S1 Web-Security Posture — Not assessed: these web-security controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks web-security controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
SC1 Supply-chain hygiene — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
X1 Async correctness — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X2 Cancellation propagation — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X3 Exception handling — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X4 Structured logging — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X5 Nullable reference types — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
Appendix A — Findings (grouped)
The findings behind the scores, grouped by severity, then by dimension and kind. The high-severity issues are enumerated in full below; items per group are capped at 25 with any overflow stated explicitly per group, never silently truncated. The complete machine-readable list of every finding (all severities) is the companion findings.md in this report's bundle.
High: github-actions-mutable-action-tag .github/workflows/ci.yml:14— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@<40-character SHA>`. This step references `actions/checkout@v3`; resolve the SHA it points at today with `gh api repos/actions/checkout/commits/v3 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/ci.yml:15— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/setup-go@<40-character SHA>`. This step references `actions/setup-go@v4`; resolve the SHA it points at today with `gh api repos/actions/setup-go/commits/v4 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/ci.yml:23— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/upload-artifact@<40-character SHA>`. This step references `actions/upload-artifact@v4`; resolve the SHA it points at today with `gh api repos/actions/upload-artifact/commits/v4 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/ci.yml:31— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@<40-character SHA>`. This step references `actions/checkout@v3`; resolve the SHA it points at today with `gh api repos/actions/checkout/commits/v3 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/ci.yml:40— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@<40-character SHA>`. This step references `actions/checkout@v3`; resolve the SHA it points at today with `gh api repos/actions/checkout/commits/v3 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/daily.yml:16— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@<40-character SHA>`. This step references `actions/checkout@v3`; resolve the SHA it points at today with `gh api repos/actions/checkout/commits/v3 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/daily.yml:17— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/setup-go@<40-character SHA>`. This step references `actions/setup-go@v4`; resolve the SHA it points at today with `gh api repos/actions/setup-go/commits/v4 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/daily.yml:25— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/upload-artifact@<40-character SHA>`. This step references `actions/upload-artifact@v4`; resolve the SHA it points at today with `gh api repos/actions/upload-artifact/commits/v4 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/docker-publish.yml:243— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@<40-character SHA>`. This step references `actions/checkout@v6`; resolve the SHA it points at today with `gh api repos/actions/checkout/commits/v6 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/docker-publish.yml:349— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@<40-character SHA>`. This step references `actions/checkout@v6`; resolve the SHA it points at today with `gh api repos/actions/checkout/commits/v6 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/npm-stage.yml:27— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/checkout@<40-character SHA>`. This step references `actions/checkout@v6`; resolve the SHA it points at today with `gh api repos/actions/checkout/commits/v6 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/npm-stage.yml:32— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/setup-go@<40-character SHA>`. This step references `actions/setup-go@v6`; resolve the SHA it points at today with `gh api repos/actions/setup-go/commits/v6 --jq .sha`.
High: github-actions-mutable-action-tag .github/workflows/npm-stage.yml:37— GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. `uses: actions/setup-node@<40-character SHA>`. This step references `actions/setup-node@v6`; resolve the SHA it points at today with `gh api repos/actions/setup-node/commits/v6 --jq .sha`.
High IaC: DS-0029 ci/release/docker/Dockerfile— 'apt-get' missing '--no-install-recommends'
High IaC: DS-0002 ci/release/linux/Dockerfile— Image user should not be 'root' A container that starts as root runs your process with root's capabilities inside the namespace, so a compromise of the process starts from there. The step: create an unprivileged account in the image (`RUN adduser --system --no-create-home app`), give it ownership of the paths the process writes at runtime (`COPY --chown=` on those layers, or a `RUN chown -R`), and end the final stage with `USER app` so it is the default at start. Build stages that only compile can stay root; it is the stage that RUNS that needs the account. If the process genuinely requires root — it manages the container runtime, ptraces another process or opens raw devices — say so here rather than making a change that breaks it.
High IaC: DS-0017 ci/release/linux/Dockerfile— 'RUN <package-manager> update' instruction alone The index refresh sits in its own layer, so the builder caches it: a later rebuild reuses the cached index and installs whatever versions it recorded, which is how an image ships packages that were patched upstream months ago. The step: this file installs with `apt-get`, so join them — `RUN apt-get update && apt-get install -y <packages>` — in one instruction, so the refresh and the install are cached and invalidated together. A refresh that genuinely has no install after it in the same image is dead weight and can go.
High IaC: DS-0029 ci/release/linux/Dockerfile— 'apt-get' missing '--no-install-recommends'
Orphaned knowledge lib/font/subsetFont.go— No living knowledge remains for this large file — its last meaningful change has decayed away; if it breaks, no one currently understands it. Schedule a read-through / add characterisation tests before it bites.
D38 · OSV Dependency Vulnerabilities· High CVE · ×1
High CVE: [GHSA redacted] go.mod— golang.org/x/image 0.20.0: [GHSA redacted] — upgrade to 0.41.0. This one row stands for the 8 advisories this scan raises against golang.org/x/image 0.20.0: [GHSA redacted], [GHSA redacted], GO-2026-4961, GO-2026-4962, GO-2026-5031, GO-2026-5061, GO-2026-5062, GO-2026-5066.
Duplicated block (9 lines × 2) d2compiler/compile.go:1050— d2compiler/compile.go:1050-1058 | d2compiler/compile.go:1079-1087 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2compiler/compile.go:1050` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2ir/d2ir.go:847— d2ir/d2ir.go:847-855 | d2ir/d2ir.go:1261-1269 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) d2ir/d2ir.go:1201— d2ir/d2ir.go:1201-1209 | d2ir/d2ir.go:1297-1305 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/d2ir.go:1201` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2ir/d2ir.go:1286— d2ir/d2ir.go:1286-1294 | d2ir/d2ir.go:1403-1411 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/d2ir.go:1286` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2layouts/d2dagrelayout/layout.go:1182— d2layouts/d2dagrelayout/layout.go:1182-1190 | d2layouts/d2dagrelayout/layout.go:1193-1202 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) d2layouts/d2dagrelayout/layout.go:1682— d2layouts/d2dagrelayout/layout.go:1682-1690 | d2layouts/d2dagrelayout/layout.go:1776-1784 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:1682` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9 lines × 2) d2oracle/edit.go:186— d2oracle/edit.go:186-194 | d2oracle/edit.go:2570-2578 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:186` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2oracle/edit.go:198— d2oracle/edit.go:198-206 | d2oracle/edit.go:2583-2591 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:198` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (9 lines × 2) d2plugin/exec.go:55— d2plugin/exec.go:55-63 | d2plugin/exec.go:128-136 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9 lines × 2) d2renderers/d2ascii/d2ascii.go:182— d2renderers/d2ascii/d2ascii.go:182-190 | d2renderers/d2ascii/d2ascii.go:202-210 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/d2ascii.go:182` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2renderers/d2ascii/d2ascii.go:378— d2renderers/d2ascii/d2ascii.go:378-386 | d2renderers/d2ascii/d2ascii.go:395-403 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) d2renderers/d2sketch/sketch.go:166— d2renderers/d2sketch/sketch.go:166-174 | d2renderers/d2sketch/sketch.go:290-298 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2sketch/sketch.go:166` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2renderers/d2svg/class.go:101— d2renderers/d2svg/class.go:101-109 | d2renderers/d2svg/table.go:120-128 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/class.go:101` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2renderers/d2svg/d2svg.go:1773— d2renderers/d2svg/d2svg.go:1773-1781 | d2renderers/d2svg/d2svg.go:1822-1830 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1773` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2cli/main.go:707— d2cli/main.go:707-715 | d2cli/main.go:814-822 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:707` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2cli/main.go:1234— d2cli/main.go:1234-1242 | d2cli/main.go:1246-1254 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:1234` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2ir/merge.go:8— d2ir/merge.go:8-16 | d2ir/merge.go:38-49 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/merge.go:8` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 2) d2renderers/d2ascii/asciishapes/class.go:20— d2renderers/d2ascii/asciishapes/class.go:20-28 | d2renderers/d2ascii/asciishapes/sqltable.go:19-27 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/asciishapes/class.go:20` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
FileTooLong: d2svg/d2svg.go d2renderers/d2svg/d2svg.go:0— FileTooLong — 2369 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2oracle/edit.go d2oracle/edit.go:0— FileTooLong — 2211 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2graph/d2graph.go d2graph/d2graph.go:0— FileTooLong — 1273 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2ir/d2ir.go d2ir/d2ir.go:0— FileTooLong — 1242 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2parser/parse.go d2parser/parse.go:0— FileTooLong — 1224 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2dagrelayout/layout.go d2layouts/d2dagrelayout/layout.go:0— FileTooLong — 1194 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2compiler/compile.go d2compiler/compile.go:0— FileTooLong — 1160 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2ir/compile.go d2ir/compile.go:0— FileTooLong — 1082 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2cli/main.go d2cli/main.go:0— FileTooLong — 1068 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2ast/d2ast.go d2ast/d2ast.go:0— FileTooLong — 1048 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2target/d2target.go d2target/d2target.go:0— FileTooLong — 863 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2elklayout/layout.go d2layouts/d2elklayout/layout.go:0— FileTooLong — 738 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2sketch/sketch.go d2renderers/d2sketch/sketch.go:0— FileTooLong — 696 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: font/subsetFont.go lib/font/subsetFont.go:0— FileTooLong — 631 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: d2grid/layout.go d2layouts/d2grid/layout.go:0— FileTooLong — 537 significant lines (blank, comment-only and punctuation-only lines excluded). To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
Duplicated block (10 lines × 2) d2ast/d2ast.go:840— d2ast/d2ast.go:840-849 | d2ast/d2ast.go:932-941 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ast/d2ast.go:840` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) d2ir/compile.go:1113— d2ir/compile.go:1113-1122 | d2ir/compile.go:1167-1176 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/compile.go:1113` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) d2ir/d2ir.go:977— d2ir/d2ir.go:977-987 | d2ir/d2ir.go:1034-1043 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/d2ir.go:977` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (10 lines × 2) d2ir/d2ir.go:1951— d2ir/d2ir.go:1951-1960 | d2ir/d2ir.go:1962-1971 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/d2ir.go:1951` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) d2oracle/edit.go:2855— d2oracle/edit.go:2855-2864 | d2oracle/edit.go:3061-3070 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) d2parser/parse.go:519— d2parser/parse.go:519-528 | d2parser/parse.go:1337-1346 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2parser/parse.go:519` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also register a scope-exit action (a `defer`-style statement) that runs when the function holding them returns: moved into a called unit it would run when THAT unit returns instead — before the caller uses what it releases — so keep the registration at the call site and extract only the work around it, or have the extracted unit hand the resource back for the caller to register.
Duplicated block (10 lines × 2) d2parser/parse.go:1727— d2parser/parse.go:1727-1736 | d2parser/parse.go:1777-1786 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2parser/parse.go:1727` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also register a scope-exit action (a `defer`-style statement) that runs when the function holding them returns: moved into a called unit it would run when THAT unit returns instead — before the caller uses what it releases — so keep the registration at the call site and extract only the work around it, or have the extracted unit hand the resource back for the caller to register.
Duplicated block (10 lines × 2) d2renderers/d2sketch/sketch.go:153— d2renderers/d2sketch/sketch.go:153-162 | d2renderers/d2sketch/sketch.go:277-286 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) d2renderers/d2svg/class.go:20— d2renderers/d2svg/class.go:20-29 | d2renderers/d2svg/table.go:48-57 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/class.go:20` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) d2renderers/d2svg/d2svg.go:1243— d2renderers/d2svg/d2svg.go:1243-1252 | d2renderers/d2svg/d2svg.go:2155-2164 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1243` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10 lines × 2) d2renderers/d2svg/d2svg.go:1800— d2renderers/d2svg/d2svg.go:1800-1809 | d2renderers/d2svg/d2svg.go:1830-1839 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) lib/geo/bezier.go:186— lib/geo/bezier.go:186-195 | lib/geo/bezier.go:262-272 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `lib/geo/bezier.go:186` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10 lines × 2) d2renderers/d2ascii/asciiroute/routing.go:197— d2renderers/d2ascii/asciiroute/routing.go:197-206 | d2renderers/d2ascii/asciiroute/routing.go:271-280 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/asciiroute/routing.go:197` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (8 lines × 2) d2compiler/compile.go:456— d2compiler/compile.go:456-463 | d2compiler/compile.go:624-631 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2compiler/compile.go:456` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) d2graph/d2graph.go:1900— d2graph/d2graph.go:1900-1907 | d2graph/layout.go:298-305 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2graph/d2graph.go:1900` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) d2ir/compile.go:1418— d2ir/compile.go:1418-1425 | d2ir/compile.go:1435-1442 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/compile.go:1418` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) d2layouts/d2dagrelayout/layout.go:326— d2layouts/d2dagrelayout/layout.go:326-333 | d2layouts/d2elklayout/layout.go:619-626 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:326` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) d2layouts/d2dagrelayout/layout.go:552— d2layouts/d2dagrelayout/layout.go:552-559 | d2layouts/d2elklayout/layout.go:1116-1123 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:552` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) d2oracle/edit.go:1238— d2oracle/edit.go:1238-1246 | d2oracle/edit.go:1257-1264 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:1238` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) d2renderers/d2sketch/sketch.go:398— d2renderers/d2sketch/sketch.go:398-405 | d2renderers/d2sketch/sketch.go:407-414 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (8 lines × 2) d2renderers/d2sketch/sketch.go:476— d2renderers/d2sketch/sketch.go:476-483 | d2renderers/d2sketch/sketch.go:619-626 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) d2renderers/d2svg/d2svg.go:666— d2renderers/d2svg/d2svg.go:666-673 | d2renderers/d2svg/d2svg.go:770-777 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) d2renderers/d2svg/d2svg.go:1413— d2renderers/d2svg/d2svg.go:1413-1420 | d2renderers/d2svg/d2svg.go:1522-1529 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) lib/color/gradient.go:135— lib/color/gradient.go:135-143 | lib/color/gradient.go:222-229 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `lib/color/gradient.go:135` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) lib/font/subsetFont.go:778— lib/font/subsetFont.go:778-785 | lib/font/subsetFont.go:792-799 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `lib/font/subsetFont.go:778` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 2) d2ir/import.go:21— d2ir/import.go:21-28 | d2ir/import.go:134-141 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/import.go:21` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 2) d2exporter/export.go:153— d2exporter/export.go:153-158 | d2exporter/export.go:388-394 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) d2graph/d2graph.go:1930— d2graph/d2graph.go:1930-1935 | d2graph/layout.go:341-346 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2graph/d2graph.go:1930` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 2) d2layouts/d2elklayout/layout.go:739— d2layouts/d2elklayout/layout.go:739-744 | d2layouts/d2elklayout/layout.go:842-847 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) d2layouts/d2elklayout/layout.go:846— d2layouts/d2elklayout/layout.go:846-851 | d2layouts/d2elklayout/layout.go:853-858 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) d2oracle/edit.go:1193— d2oracle/edit.go:1193-1198 | d2oracle/edit.go:2042-2047 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:1193` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 2) d2oracle/edit.go:1577— d2oracle/edit.go:1577-1582 | d2oracle/edit.go:1584-1589 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) d2renderers/d2sketch/sketch.go:606— d2renderers/d2sketch/sketch.go:606-612 | d2renderers/d2svg/class.go:108-113 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (6 lines × 2) d2renderers/d2svg/class.go:134— d2renderers/d2svg/class.go:134-140 | d2renderers/d2svg/table.go:159-164 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/class.go:134` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 2) d2renderers/d2svg/d2svg.go:1759— d2renderers/d2svg/d2svg.go:1759-1764 | d2renderers/d2svg/d2svg.go:1796-1801 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1759` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 2) lib/shape/shape_circle.go:26— lib/shape/shape_circle.go:26-31 | lib/shape/shape_oval.go:28-33 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once.
Duplicated block (6 lines × 2) d2renderers/d2ascii/asciishapes/class.go:14— d2renderers/d2ascii/asciishapes/class.go:14-19 | d2renderers/d2ascii/asciishapes/sqltable.go:13-18 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/asciishapes/class.go:14` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (6 lines × 2) d2renderers/d2ascii/asciishapes/helpers.go:58— d2renderers/d2ascii/asciishapes/helpers.go:58-63 | d2renderers/d2ascii/asciishapes/helpers.go:72-77 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/asciishapes/helpers.go:58` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 2) d2renderers/d2ascii/asciishapes/parallelogram.go:4— d2renderers/d2ascii/asciishapes/parallelogram.go:4-9 | d2renderers/d2ascii/asciishapes/queue.go:4-9 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/asciishapes/parallelogram.go:4` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) d2compiler/compile.go:282— d2compiler/compile.go:282-292 | d2compiler/compile.go:896-906 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2compiler/compile.go:282` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) d2format/format.go:260— d2format/format.go:260-270 | d2format/format.go:316-326 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2format/format.go:260` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) d2ir/compile.go:893— d2ir/compile.go:893-904 | d2ir/compile.go:931-941 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/compile.go:893` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) d2oracle/edit.go:2376— d2oracle/edit.go:2376-2386 | d2oracle/edit.go:2421-2431 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:2376` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) d2parser/parse.go:579— d2parser/parse.go:579-589 | d2parser/parse.go:1402-1412 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2parser/parse.go:579` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also register a scope-exit action (a `defer`-style statement) that runs when the function holding them returns: moved into a called unit it would run when THAT unit returns instead — before the caller uses what it releases — so keep the registration at the call site and extract only the work around it, or have the extracted unit hand the resource back for the caller to register.
Duplicated block (11 lines × 2) d2plugin/exec.go:173— d2plugin/exec.go:173-183 | d2plugin/exec.go:249-259 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2plugin/exec.go:173` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) d2renderers/d2sketch/sketch.go:110— d2renderers/d2sketch/sketch.go:110-120 | d2renderers/d2sketch/sketch.go:185-195 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2sketch/sketch.go:110` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (11 lines × 2) d2renderers/d2svg/class.go:154— d2renderers/d2svg/class.go:154-164 | d2renderers/d2svg/table.go:172-182 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/class.go:154` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) d2renderers/d2svg/d2svg.go:1161— d2renderers/d2svg/d2svg.go:1161-1171 | d2renderers/d2svg/d2svg.go:2011-2021 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1161` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) d2renderers/d2svg/d2svg.go:2023— d2renderers/d2svg/d2svg.go:2023-2033 | d2renderers/d2svg/d2svg.go:2048-2058 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:2023` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) d2cli/main.go:605— d2cli/main.go:605-615 | d2cli/main.go:689-699 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:605` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (11 lines × 2) d2cli/main.go:719— d2cli/main.go:719-729 | d2cli/main.go:832-842 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:719` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) d2ast/d2ast.go:1331— d2ast/d2ast.go:1331-1344 | d2ast/d2ast.go:1435-1448 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ast/d2ast.go:1331` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) d2layouts/d2dagrelayout/layout.go:451— d2layouts/d2dagrelayout/layout.go:451-464 | d2layouts/d2dagrelayout/layout.go:511-524 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:451` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) d2oracle/edit.go:1037— d2oracle/edit.go:1037-1050 | d2oracle/edit.go:1092-1106 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:1037` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14 lines × 2) d2oracle/edit.go:2840— d2oracle/edit.go:2840-2853 | d2oracle/edit.go:3046-3059 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:2840` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (14 lines × 2) d2renderers/d2ascii/asciiroute/labels.go:139— d2renderers/d2ascii/asciiroute/labels.go:139-152 | d2renderers/d2ascii/asciiroute/labels.go:171-184 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/asciiroute/labels.go:139` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (14 lines × 2) d2renderers/d2sketch/sketch.go:231— d2renderers/d2sketch/sketch.go:231-244 | d2renderers/d2sketch/sketch.go:308-321 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2sketch/sketch.go:231` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (14 lines × 2) d2renderers/d2svg/d2svg.go:1222— d2renderers/d2svg/d2svg.go:1222-1235 | d2renderers/d2svg/d2svg.go:2121-2134 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1222` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) lib/font/subsetFont.go:602— lib/font/subsetFont.go:602-615 | lib/font/subsetFont.go:620-633 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `lib/font/subsetFont.go:602` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (14 lines × 2) d2graph/layout.go:442— d2graph/layout.go:442-455 | d2graph/layout.go:473-486 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2graph/layout.go:442` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) d2graph/layout.go:524— d2graph/layout.go:524-537 | d2graph/layout.go:556-569 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2graph/layout.go:524` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) d2ast/d2ast.go:1364— d2ast/d2ast.go:1364-1375 | d2ast/d2ast.go:1406-1417 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) d2ast/d2ast.go:1400— d2ast/d2ast.go:1400-1411 | d2ast/d2ast.go:1493-1504 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ast/d2ast.go:1400` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12 lines × 2) d2format/format.go:110— d2format/format.go:110-121 | d2format/format.go:188-199 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2format/format.go:110` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) d2layouts/d2dagrelayout/layout.go:418— d2layouts/d2dagrelayout/layout.go:418-429 | d2layouts/d2dagrelayout/layout.go:482-493 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:418` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) d2oracle/edit.go:2877— d2oracle/edit.go:2877-2888 | d2oracle/edit.go:3195-3206 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (12 lines × 2) d2renderers/d2ascii/d2ascii.go:167— d2renderers/d2ascii/d2ascii.go:167-178 | d2renderers/d2ascii/d2ascii.go:187-198 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2ascii/d2ascii.go:167` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) d2renderers/d2svg/d2svg.go:1858— d2renderers/d2svg/d2svg.go:1858-1869 | d2renderers/d2svg/d2svg.go:1890-1901 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1858` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (12 lines × 2) d2cli/main.go:429— d2cli/main.go:429-440 | d2cli/main.go:454-465 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:429` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (12 lines × 2) d2graph/layout.go:186— d2graph/layout.go:186-197 | d2graph/layout.go:240-251 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2graph/layout.go:186` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 2) d2ast/d2ast.go:814— d2ast/d2ast.go:814-826 | d2ast/d2ast.go:896-908 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ast/d2ast.go:814` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 2) d2ir/compile.go:871— d2ir/compile.go:871-883 | d2ir/compile.go:907-919 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/compile.go:871` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 2) d2ir/d2ir.go:903— d2ir/d2ir.go:903-915 | d2ir/d2ir.go:927-939 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2ir/d2ir.go:903` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (13 lines × 2) d2layouts/d2dagrelayout/layout.go:1114— d2layouts/d2dagrelayout/layout.go:1114-1126 | d2layouts/d2dagrelayout/layout.go:1155-1168 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:1114` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (13 lines × 2) d2renderers/d2sketch/sketch.go:442— d2renderers/d2sketch/sketch.go:442-454 | d2renderers/d2sketch/sketch.go:584-596 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) d2renderers/d2svg/d2svg.go:289— d2renderers/d2svg/d2svg.go:289-301 | d2renderers/d2svg/d2svg.go:336-348 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) d2cli/main.go:1045— d2cli/main.go:1045-1057 | d2cli/main.go:1153-1165 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:1045` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7 lines × 2) d2layouts/d2dagrelayout/layout.go:1097— d2layouts/d2dagrelayout/layout.go:1097-1103 | d2layouts/d2dagrelayout/layout.go:1139-1145 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:1097` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (7 lines × 2) d2oracle/edit.go:1836— d2oracle/edit.go:1836-1843 | d2oracle/edit.go:2795-2801 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (7 lines × 2) d2renderers/d2svg/d2svg.go:1429— d2renderers/d2svg/d2svg.go:1429-1436 | d2renderers/d2svg/d2svg.go:1553-1559 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1429` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7 lines × 2) d2renderers/d2svg/d2svg.go:2203— d2renderers/d2svg/d2svg.go:2203-2209 | d2renderers/d2svg/table.go:19-25 — the copies sit in sibling files of one directory: extract the block into a single shared function in that directory and call it from each site, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:2203` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (7 lines × 2) d2cli/main.go:859— d2cli/main.go:859-865 | d2cli/main.go:866-872 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:859` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7 lines × 2) d2cli/main.go:1096— d2cli/main.go:1096-1102 | d2cli/main.go:1106-1112 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2cli/main.go:1096` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Medium IaC: DS-0001 ci/release/docker/Dockerfile— ':latest' tag used A `:latest` base pins nothing: the stage rebuilds against whatever that tag points at on the day, so the same commit produces different images and a change you did not make arrives without a diff. The step: pin the base to a concrete release and, where the registry offers one, its digest — `FROM alpine:3.21@sha256:…` — then bump it deliberately, which is a review a bot can raise. A build stage that only compiles is worth pinning for the same reason: it decides what ends up in the layers you ship.
Medium IaC: CKV_DOCKER_4 ci/release/docker/Dockerfile:22— Ensure that COPY is used instead of ADD in Dockerfiles
Medium IaC: CKV_DOCKER_7 ci/release/docker/Dockerfile:2— Ensure the base image uses a non latest version tag
Medium IaC: CKV_DOCKER_2 ci/release/docker/Dockerfile:1— Ensure that HEALTHCHECK instructions have been added to container images
Medium IaC: CKV_DOCKER_3 ci/release/linux/Dockerfile:1— Ensure that a user for the container has been created
D38 · OSV Dependency Vulnerabilities· Medium CVE · ×5
Medium CVE: GO-2026-5320 go.mod— github.com/yuin/goldmark 1.7.4 (github.com/yuin/goldmark/renderer/html): GO-2026-5320 — upgrade to 1.7.17
Medium CVE: [GHSA redacted] go.mod— golang.org/x/net 0.35.0: [GHSA redacted] — upgrade to 0.55.0. This one row stands for the 12 advisories this scan raises against golang.org/x/net 0.35.0: [GHSA redacted], [GHSA redacted], [GHSA redacted], GO-2026-4440, GO-2026-4441, GO-2026-4918, GO-2026-5025, GO-2026-5026, GO-2026-5027, GO-2026-5029, GO-2026-5030, GO-2026-5942.
Medium CVE: GO-2026-5024 go.mod— golang.org/x/sys 0.30.0 (golang.org/x/sys/windows): GO-2026-5024 — golang.org/x/sys is not a DIRECT requirement of this module: go.mod records it as `// indirect`, pulled in transitively, so raise it in place (run `go get golang.org/x/sys@v0.44.0`, which updates the require line go.mod already holds for it).
Medium CVE: GO-2026-5970 go.mod— golang.org/x/text 0.22.0 (golang.org/x/text/unicode/norm): GO-2026-5970 — upgrade to 0.39.0
Medium CVE: GO-2025-3955 go.mod— stdlib 1.25.0 (net/http): GO-2025-3955 — fixed in Go 1.25.1; pin a build toolchain at or above it (go.mod `toolchain` directive, or your CI's Go version) — the `go` directive is a minimum language version, not the compiler that builds your binaries. This one row stands for the 39 advisories this scan raises against stdlib 1.25.0: GO-2025-3955, GO-2025-4006, GO-2025-4007, GO-2025-4008, GO-2025-4009, GO-2025-4010, GO-2025-4011, GO-2025-4012, GO-2025-4013, GO-2025-4014, GO-2025-4015, GO-2025-4155, GO-2025-4175, GO-2026-4337, GO-2026-4340, GO-2026-4341, GO-2026-4342, GO-2026-4601, GO-2026-4602, GO-2026-4603, GO-2026-4864, GO-2026-4865, GO-2026-4869, GO-2026-4870, GO-2026-4918, GO-2026-4946, GO-2026-4947, GO-2026-4970, GO-2026-4971, GO-2026-4976, GO-2026-4977, GO-2026-4980, GO-2026-4981, GO-2026-4982, GO-2026-4986, GO-2026-5037, GO-2026-5038, GO-2026-5039, GO-2026-5856.
Duplicated block (5 lines × 2) d2compiler/compile.go:385— d2compiler/compile.go:385-389 | d2compiler/compile.go:601-606 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2compiler/compile.go:601` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (5 lines × 2) d2graph/d2graph.go:1353— d2graph/d2graph.go:1353-1357 | d2graph/d2graph.go:1367-1371 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2graph/d2graph.go:1353` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (5 lines × 2) d2layouts/d2dagrelayout/layout.go:547— d2layouts/d2dagrelayout/layout.go:547-551 | d2layouts/d2grid/layout.go:192-197 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:547` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (5 lines × 2) d2layouts/d2grid/layout.go:158— d2layouts/d2grid/layout.go:158-162 | d2layouts/d2layouts.go:351-355 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2grid/layout.go:158` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (5 lines × 2) d2renderers/d2svg/d2svg.go:1382— d2renderers/d2svg/d2svg.go:1382-1386 | d2renderers/d2svg/d2svg.go:1478-1482 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1382` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Medium: math-random-used d2chaos/d2chaos.go:5— `math/rand` is not cryptographically secure — its stream is reproducible from its seed and predictable from observed output — so any value that must be unguessable (a token, nonce, key, salt, session id, password-reset or MFA code) has to come from `crypto/rand`. Where non-cryptographic randomness IS the intent — jitter, backoff, sampling, load spreading, simulation, test fixtures, or output that is deliberately reproducible from a seed — `math/rand` is the correct choice and no change is needed; a package that deliberately offers both should keep its security-sensitive callers on the `crypto/rand` path rather than drop the other one. This is a semgrep security-AUDIT rule: it reports that a sensitive pattern is present, not that it is exploitable here. Confirm whether the flagged value reaches a security decision — a credential, token, nonce, key, salt or session id, or an externally reachable surface — and apply the change where it does; where it provably does not (cosmetic, simulation, or deliberately reproducible use), record the review and leave the code as it is.
Medium: var-in-href e2etests/report/template.html:13— Detected a template variable used in an anchor tag with the 'href' attribute. This allows a malicious actor to input the 'javascript:' URI and is subject to cross- site scripting (XSS) attacks. Emit the link through your template layer's URL construction: a helper that percent-encodes the value and rejects any scheme other than http/https, rather than interpolating it raw. Where the template engine is a third-party generator you do not control, validate the value before it reaches the template. You may also consider setting the Content Security Policy (CSP) header. This is a semgrep security-AUDIT rule: it reports that a sensitive construct is present, not that it is exploitable here. Confirm whether this site handles untrusted input or is reachable across a trust boundary — and apply the change where it is; where the construct is required by the platform or protocol it calls into, and carries no untrusted data (a syscall/FFI shim, a build- or debug-gated tool, a fixed local surface), record the review and leave the code as it is.
Medium: use-of-sha1 lib/color/gradient.go:238— Detected SHA1 hash algorithm which is considered insecure. SHA1 is not collision resistant and is therefore not suitable as a cryptographic signature. Use SHA256 or SHA3 instead. This is a semgrep security-AUDIT rule: it reports that a sensitive pattern is present, not that it is exploitable here. Confirm whether the flagged value reaches a security decision — a credential, token, nonce, key, salt or session id, or an externally reachable surface — and apply the change where it does; where it provably does not (cosmetic, simulation, or deliberately reproducible use), record the review and leave the code as it is.
Medium: potential-dos-via-decompression-bomb lib/urlenc/urlenc.go:45— Detected a possible denial-of-service via a zip bomb attack. By limiting the max bytes read, you can mitigate this attack. `io.CopyN()` can specify a size. This is a semgrep security-AUDIT rule: it reports that a sensitive construct is present, not that it is exploitable here. Confirm whether this site handles untrusted input or is reachable across a trust boundary — and apply the change where it is; where the construct is required by the platform or protocol it calls into, and carries no untrusted data (a syscall/FFI shim, a build- or debug-gated tool, a fixed local surface), record the review and leave the code as it is.
TooManyMethods: Object d2graph/d2graph.go:165— TooManyMethods — 50 methods, declared across 4 files: d2graph/d2graph.go (29), d2graph/layout.go (9), d2graph/seqdiagram.go (8), d2graph/grid_diagram.go (4). That list is where to read them, not a suggestion to split the file: the members belong to the type wherever they are declared, so moving them between files leaves the count unchanged. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: Map d2ir/d2ir.go:168— TooManyMethods — 42 methods, declared across 4 files: d2ir/d2ir.go (36), d2ir/pattern.go (3), d2ir/query.go (2), d2ir/compile.go (1). That list is where to read them, not a suggestion to split the file: the members belong to the type wherever they are declared, so moving them between files leaves the count unchanged. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: parser d2parser/parse.go:142— TooManyMethods — 33 methods. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
TooManyMethods: compiler d2ir/compile.go:31— TooManyMethods — 31 methods, declared across 3 files: d2ir/compile.go (25), d2ir/import.go (5), d2ir/d2ir.go (1). That list is where to read them, not a suggestion to split the file: the members belong to the type wherever they are declared, so moving them between files leaves the count unchanged. To reduce it, group the members that share the same data into a smaller type of their own and delegate to it, so no single type carries every responsibility.
Duplicated block (16 lines × 2) d2layouts/d2dagrelayout/layout.go:1482— d2layouts/d2dagrelayout/layout.go:1482-1497 | d2layouts/d2dagrelayout/layout.go:1553-1568 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:1482` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16 lines × 2) d2oracle/edit.go:2951— d2oracle/edit.go:2951-2966 | d2oracle/edit.go:3139-3156 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:2951` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16 lines × 2) d2parser/parse.go:429— d2parser/parse.go:429-448 | d2parser/parse.go:1541-1556 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2parser/parse.go:429` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16 lines × 2) d2renderers/d2svg/d2svg.go:1445— d2renderers/d2svg/d2svg.go:1445-1460 | d2renderers/d2svg/d2svg.go:1567-1584 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:1445` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15 lines × 2) d2layouts/d2dagrelayout/layout.go:1711— d2layouts/d2dagrelayout/layout.go:1711-1725 | d2layouts/d2dagrelayout/layout.go:1728-1742 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2layouts/d2dagrelayout/layout.go:1711` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15 lines × 2) d2oracle/edit.go:126— d2oracle/edit.go:126-140 | d2oracle/edit.go:2515-2529 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15 lines × 2) d2renderers/d2sketch/sketch.go:945— d2renderers/d2sketch/sketch.go:945-959 | d2renderers/d2sketch/sketch.go:984-998 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2sketch/sketch.go:945` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) d2oracle/edit.go:166— d2oracle/edit.go:166-182 | d2oracle/edit.go:2548-2564 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2oracle/edit.go:166` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) d2renderers/d2svg/d2svg.go:160— d2renderers/d2svg/d2svg.go:160-176 | d2renderers/d2svg/d2svg.go:2915-2931 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `d2renderers/d2svg/d2svg.go:160` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
d2oracle._set (cyclomatic 182) d2oracle/edit.go:327— d2oracle._set has cyclomatic complexity 182 (threshold 15). Of this number, 176 points are the body's own statements and 6 belong to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.move (cyclomatic 121) d2oracle/edit.go:1767— d2oracle.move has cyclomatic complexity 121 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2svg.drawShape (cyclomatic 107) d2renderers/d2svg/d2svg.go:1602— d2svg.drawShape has cyclomatic complexity 107 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.fitPadding (cyclomatic 103) d2layouts/d2dagrelayout/layout.go:1339— d2dagrelayout.fitPadding has cyclomatic complexity 103 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.shiftReachableDown (cyclomatic 102) d2layouts/d2dagrelayout/layout.go:765— d2dagrelayout.shiftReachableDown has cyclomatic complexity 102 (threshold 15). Of this number, 26 points are the body's own statements and 76 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2elklayout.Layout (cyclomatic 101) d2layouts/d2elklayout/layout.go:154— d2elklayout.Layout has cyclomatic complexity 101 (threshold 15). Of this number, 75 points are the body's own statements and 26 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Ruler.measureNode (cyclomatic 92) lib/textmeasure/markdown.go:217— Ruler.measureNode has cyclomatic complexity 92 (threshold 15). Of this number, 89 points are the body's own statements and 3 belong to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2cli.Run (cyclomatic 89) d2cli/main.go:52— d2cli.Run has cyclomatic complexity 89 (threshold 15). Of this number, 88 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
d2svg.Render (cyclomatic 78) d2renderers/d2svg/d2svg.go:2733— d2svg.Render has cyclomatic complexity 78 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler.compileReserved (cyclomatic 72) d2compiler/compile.go:537— compiler.compileReserved has cyclomatic complexity 72 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Style.Apply (cyclomatic 70) d2graph/d2graph.go:315— Style.Apply has cyclomatic complexity 70 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Graph.SetDimensions (cyclomatic 64) d2graph/d2graph.go:1502— Graph.SetDimensions has cyclomatic complexity 64 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Map.ensureField (cyclomatic 64) d2ir/d2ir.go:858— Map.ensureField has cyclomatic complexity 64 (threshold 15). Of this number, 48 points are the body's own statements and 16 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.Layout (cyclomatic 64) d2layouts/d2dagrelayout/layout.go:72— d2dagrelayout.Layout has cyclomatic complexity 64 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2svg.drawConnection (cyclomatic 58) d2renderers/d2svg/d2svg.go:1006— d2svg.drawConnection has cyclomatic complexity 58 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler.ampersandFilter (cyclomatic 57) d2ir/compile.go:718— compiler.ampersandFilter has cyclomatic complexity 57 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler._compileEdges (cyclomatic 52) d2ir/compile.go:1392— compiler._compileEdges has cyclomatic complexity 52 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.adjustRankSpacing (cyclomatic 52) d2layouts/d2dagrelayout/layout.go:1078— d2dagrelayout.adjustRankSpacing has cyclomatic complexity 52 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler._compileField (cyclomatic 49) d2ir/compile.go:1058— compiler._compileField has cyclomatic complexity 49 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2graph.CompareSerializedObject (cyclomatic 47) d2graph/serde.go:211— d2graph.CompareSerializedObject has cyclomatic complexity 47 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
compiler.resolveSubstitutions (cyclomatic 46) d2ir/compile.go:228— compiler.resolveSubstitutions has cyclomatic complexity 46 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2layouts.LayoutNested (cyclomatic 46) d2layouts/d2layouts.go:78— d2layouts.LayoutNested has cyclomatic complexity 46 (threshold 15). Of this number, 45 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Edge.TraceToShape (cyclomatic 45) d2graph/layout.go:414— Edge.TraceToShape has cyclomatic complexity 45 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.ReconnectEdge (cyclomatic 44) d2oracle/edit.go:124— d2oracle.ReconnectEdge has cyclomatic complexity 44 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.DeleteIDDeltas (cyclomatic 42) d2oracle/edit.go:2970— d2oracle.DeleteIDDeltas has cyclomatic complexity 42 (threshold 15). Of this number, 34 points are the body's own statements and 8 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ASCIIartist.Render (cyclomatic 42) d2renderers/d2ascii/d2ascii.go:222— ASCIIartist.Render has cyclomatic complexity 42 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
ThemableElement.Render (cyclomatic 42) d2themes/element.go:111— ThemableElement.Render has cyclomatic complexity 42 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Key.Equals (cyclomatic 41) d2ast/d2ast.go:895— Key.Equals has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2cli.compile (cyclomatic 41) d2cli/main.go:490— d2cli.compile has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2exporter.toConnection (cyclomatic 41) d2exporter/export.go:338— d2exporter.toConnection has cyclomatic complexity 41 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
d2grid.Layout (cyclomatic 41) d2layouts/d2grid/layout.go:25— d2grid.Layout has cyclomatic complexity 41 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.Delete (cyclomatic 40) d2oracle/edit.go:938— d2oracle.Delete has cyclomatic complexity 40 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.MoveIDDeltas (cyclomatic 40) d2oracle/edit.go:2776— d2oracle.MoveIDDeltas has cyclomatic complexity 40 (threshold 15). Of this number, 28 points are the body's own statements and 12 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Object.GetFill (cyclomatic 38) d2graph/d2graph.go:512— Object.GetFill has cyclomatic complexity 38 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
d2lsp.getKeywordContext (cyclomatic 38) d2lsp/completion.go:103— d2lsp.getKeywordContext has cyclomatic complexity 38 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2exporter.applyTheme (cyclomatic 37) d2exporter/export.go:80— d2exporter.applyTheme has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2elklayout.deleteBends (cyclomatic 37) d2layouts/d2elklayout/layout.go:661— d2elklayout.deleteBends has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.updateNear (cyclomatic 37) d2oracle/edit.go:2330— d2oracle.updateNear has cyclomatic complexity 37 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler.compileField (cyclomatic 36) d2compiler/compile.go:346— compiler.compileField has cyclomatic complexity 36 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Canvas.ToByteArray (cyclomatic 36) d2renderers/d2ascii/asciicanvas/asciicanvas.go:76— Canvas.ToByteArray has cyclomatic complexity 36 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2cli.loadFonts (cyclomatic 35) d2cli/main.go:1320— d2cli.loadFonts has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.deleteReserved (cyclomatic 35) d2oracle/edit.go:1314— d2oracle.deleteReserved has cyclomatic complexity 35 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.parseUnquotedString (cyclomatic 35) d2parser/parse.go:1068— parser.parseUnquotedString has cyclomatic complexity 35 (threshold 15). Of this number, 31 points are the body's own statements and 4 belong to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
main.main (cyclomatic 35) e2etests/report/main.go:34— main.main has cyclomatic complexity 35 (threshold 15). Of this number, 19 points are the body's own statements and 16 belong to 2 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Key.D2OracleEquals (cyclomatic 34) d2ast/d2ast.go:813— Key.D2OracleEquals has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.renameConflictsToParent (cyclomatic 34) d2oracle/edit.go:1163— d2oracle.renameConflictsToParent has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Map.createEdge (cyclomatic 33) d2ir/d2ir.go:1272— Map.createEdge has cyclomatic complexity 33 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.deleteObject (cyclomatic 33) d2oracle/edit.go:1525— d2oracle.deleteObject has cyclomatic complexity 33 (threshold 15). Of this number, 32 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2svg.arrowheadMarker (cyclomatic 33) d2renderers/d2svg/d2svg.go:454— d2svg.arrowheadMarker has cyclomatic complexity 33 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
gridDiagram.layoutDynamic (cyclomatic 32) d2layouts/d2grid/layout.go:324— gridDiagram.layoutDynamic has cyclomatic complexity 32 (threshold 15). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
d2oracle.ReconnectEdgeIDDeltas (cyclomatic 32) d2oracle/edit.go:2502— d2oracle.ReconnectEdgeIDDeltas has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler.validateKey (cyclomatic 31) d2compiler/compile.go:1098— compiler.validateKey has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler.compileMap (cyclomatic 31) d2ir/compile.go:502— compiler.compileMap has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Graph.Texts (cyclomatic 30) d2graph/d2graph.go:1697— Graph.Texts has cyclomatic complexity 30 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
gridDiagram.getBestLayout (cyclomatic 29) d2layouts/d2grid/layout.go:550— gridDiagram.getBestLayout has cyclomatic complexity 29 (threshold 15). Of this number, 18 points are the body's own statements and 11 belong to 3 function literals inside it that branch. To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Diagram.BoundingBox (cyclomatic 29) d2target/d2target.go:277— Diagram.BoundingBox has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
printer._map (cyclomatic 28) d2format/format.go:287— printer._map has cyclomatic complexity 28 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
asciishapes.DrawPerson (cyclomatic 27) d2renderers/d2ascii/asciishapes/person.go:5— asciishapes.DrawPerson has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
asciishapes.DrawCylinder (cyclomatic 26) d2renderers/d2ascii/asciishapes/cylinder.go:3— asciishapes.DrawCylinder has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2compiler.compileThemeOverrides (cyclomatic 25) d2compiler/compile.go:1591— d2compiler.compileThemeOverrides has cyclomatic complexity 25 (threshold 15). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Where every arm is uniform — the same kind of value, with no behaviour of its own — a table keyed by the case is the shorter form; wherever the arms carry different data or different behaviour, keep them as cases, because collapsing those trades an explicit, reviewable set of cases for nothing.
d2dagrelayout.adjustDeltaForEdges (cyclomatic 25) d2layouts/d2dagrelayout/layout.go:1666— d2dagrelayout.adjustDeltaForEdges has cyclomatic complexity 25 (threshold 15). Most of this is not in the body itself: 12 of the 25 points are its own statements and the rest belongs to one function literal inside it that branches (line 1667). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
asciishapes.DrawDocument (cyclomatic 25) d2renderers/d2ascii/asciishapes/document.go:5— asciishapes.DrawDocument has cyclomatic complexity 25 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
compiler.compileMap (cyclomatic 24) d2compiler/compile.go:274— compiler.compileMap has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Object.GetDefaultSize (cyclomatic 24) d2graph/d2graph.go:995— Object.GetDefaultSize has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Object.SpacingOpt (cyclomatic 24) d2graph/d2graph.go:1885— Object.SpacingOpt has cyclomatic complexity 24 (threshold 15). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Where every arm is uniform — the same kind of value, with no behaviour of its own — a table keyed by the case is the shorter form; wherever the arms carry different data or different behaviour, keep them as cases, because collapsing those trades an explicit, reviewable set of cases for nothing.
compiler.extendLinks (cyclomatic 24) d2ir/compile.go:1238— compiler.extendLinks has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.shiftDown (cyclomatic 24) d2layouts/d2dagrelayout/layout.go:633— d2dagrelayout.shiftDown has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.shiftUp (cyclomatic 24) d2layouts/d2dagrelayout/layout.go:697— d2dagrelayout.shiftUp has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2plugin.FeatureSupportCheck (cyclomatic 24) d2plugin/plugin_features.go:27— d2plugin.FeatureSupportCheck has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
asciishapes.DrawQueue (cyclomatic 24) d2renderers/d2ascii/asciishapes/queue.go:3— asciishapes.DrawQueue has cyclomatic complexity 24 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
d2svg.RenderLegend (cyclomatic 24) d2renderers/d2svg/d2svg.go:181— d2svg.RenderLegend has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2cli._render (cyclomatic 23) d2cli/main.go:909— d2cli._render has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
ASCIIartist.calculateExtendedBounds (cyclomatic 23) d2renderers/d2ascii/d2ascii.go:140— ASCIIartist.calculateExtendedBounds has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2target.ToArrowhead (cyclomatic 23) d2target/d2target.go:938— d2target.ToArrowhead has cyclomatic complexity 23 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
compiler.validateNear (cyclomatic 22) d2compiler/compile.go:1170— compiler.validateNear has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
printer.mapKey (cyclomatic 22) d2format/format.go:367— printer.mapKey has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.generateUniqueKey (cyclomatic 22) d2oracle/edit.go:2648— d2oracle.generateUniqueKey has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
asciishapes.DrawStoredData (cyclomatic 22) d2renderers/d2ascii/asciishapes/stored_data.go:7— asciishapes.DrawStoredData has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Diagram.GetBoard (cyclomatic 22) d2target/d2target.go:106— Diagram.GetBoard has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2cli.render (cyclomatic 21) d2cli/main.go:813— d2cli.render has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2cli.renderPPTX (cyclomatic 21) d2cli/main.go:1133— d2cli.renderPPTX has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
watcher.watchLoop (cyclomatic 21) d2cli/watch.go:225— watcher.watchLoop has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2compiler.compileConfig (cyclomatic 21) d2compiler/compile.go:1505— d2compiler.compileConfig has cyclomatic complexity 21 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
d2graph.CompareSerializedEdge (cyclomatic 21) d2graph/serde.go:357— d2graph.CompareSerializedEdge has cyclomatic complexity 21 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Object.GetMargin (cyclomatic 21) d2graph/layout.go:289— Object.GetMargin has cyclomatic complexity 21 (threshold 15). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Where every arm is uniform — the same kind of value, with no behaviour of its own — a table keyed by the case is the shorter form; wherever the arms carry different data or different behaviour, keep them as cases, because collapsing those trades an explicit, reviewable set of cases for nothing.
compiler.compileLink (cyclomatic 21) d2ir/compile.go:1305— compiler.compileLink has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.adjustCrossRankSpacing (cyclomatic 21) d2layouts/d2dagrelayout/layout.go:1261— d2dagrelayout.adjustCrossRankSpacing has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.RenameIDDeltas (cyclomatic 21) d2oracle/edit.go:3161— d2oracle.RenameIDDeltas has cyclomatic complexity 21 (threshold 15). Of this number, 15 points are the body's own statements and 6 belong to 3 function literals inside it that branch. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.parseMap (cyclomatic 21) d2parser/parse.go:386— parser.parseMap has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.parseBlockString (cyclomatic 21) d2parser/parse.go:1397— parser.parseBlockString has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2svg.singleThemeRulesets (cyclomatic 21) d2renderers/d2svg/d2svg.go:3142— d2svg.singleThemeRulesets has cyclomatic complexity 21 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Theme.ApplyOverrides (cyclomatic 21) d2themes/d2themes.go:33— Theme.ApplyOverrides has cyclomatic complexity 21 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
color.Darken (cyclomatic 21) lib/color/color.go:22— color.Darken has cyclomatic complexity 21 (threshold 15). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Where every arm is uniform — the same kind of value, with no behaviour of its own — a table keyed by the case is the shorter form; wherever the arms carry different data or different behaviour, keep them as cases, because collapsing those trades an explicit, reviewable set of cases for nothing.
d2cli.resolveLinks (cyclomatic 20) d2cli/main.go:706— d2cli.resolveLinks has cyclomatic complexity 20 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
compiler.compileSubstitutions (cyclomatic 20) d2ir/compile.go:127— compiler.compileSubstitutions has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler.IsContainer (cyclomatic 20) d2ir/d2ir.go:708— compiler.IsContainer has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Map.DeleteField (cyclomatic 20) d2ir/d2ir.go:1089— Map.DeleteField has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.adjustEdges (cyclomatic 20) d2layouts/d2dagrelayout/layout.go:1756— d2dagrelayout.adjustEdges has cyclomatic complexity 20 (threshold 15). Most of this is not in the body itself: 4 of the 20 points are its own statements and the rest belongs to one function literal inside it that branches (line 1757). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
d2sequence.newSequenceDiagram (cyclomatic 20) d2layouts/d2sequence/sequence_diagram.go:77— d2sequence.newSequenceDiagram has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2cli.renderPDF (cyclomatic 19) d2cli/main.go:1021— d2cli.renderPDF has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2exporter.applyStyles (cyclomatic 19) d2exporter/export.go:152— d2exporter.applyStyles has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
compiler.validateConfigs (cyclomatic 19) d2ir/compile.go:172— compiler.validateConfigs has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Map.getEdges (cyclomatic 19) d2ir/d2ir.go:1179— Map.getEdges has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.getLongestEdgeChainHead (cyclomatic 19) d2layouts/d2dagrelayout/layout.go:414— d2dagrelayout.getLongestEdgeChainHead has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2near.place (cyclomatic 19) d2layouts/d2near/layout.go:95— d2near.place has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2near.boundingBox (cyclomatic 19) d2layouts/d2near/layout.go:151— d2near.boundingBox has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
asciishapes.DrawPackage (cyclomatic 19) d2renderers/d2ascii/asciishapes/package.go:5— asciishapes.DrawPackage has cyclomatic complexity 19 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
asciishapes.DrawStep (cyclomatic 19) d2renderers/d2ascii/asciishapes/step.go:3— asciishapes.DrawStep has cyclomatic complexity 19 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
d2svg.dimensions (cyclomatic 19) d2renderers/d2svg/d2svg.go:99— d2svg.dimensions has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
pptx.Validate (cyclomatic 19) lib/pptx/validate.go:13— pptx.Validate has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2ast.RawString (cyclomatic 18) d2ast/d2ast.go:1563— d2ast.RawString has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
compiler.compilePosition (cyclomatic 18) d2compiler/compile.go:478— compiler.compilePosition has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2exporter.toShape (cyclomatic 18) d2exporter/export.go:209— d2exporter.toShape has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Object.FindEdges (cyclomatic 18) d2graph/d2graph.go:820— Object.FindEdges has cyclomatic complexity 18 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
Object.ShiftDescendants (cyclomatic 18) d2graph/layout.go:103— Object.ShiftDescendants has cyclomatic complexity 18 (threshold 15). Most of this is not in the body itself: 5 of the 18 points are its own statements and the rest belongs to one function literal inside it that branches (line 119). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
Map.FindBoardRoot (cyclomatic 18) d2ir/d2ir.go:1937— Map.FindBoardRoot has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
gridDiagram.layoutEvenly (cyclomatic 18) d2layouts/d2grid/layout.go:232— gridDiagram.layoutEvenly has cyclomatic complexity 18 (threshold 15). Of this number, 16 points are the body's own statements and 2 belong to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
sequenceDiagram.adjustGroupLabel (cyclomatic 18) d2layouts/d2sequence/sequence_diagram.go:312— sequenceDiagram.adjustGroupLabel has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.deleteObjField (cyclomatic 18) d2oracle/edit.go:1478— d2oracle.deleteObjField has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle._updateImport (cyclomatic 18) d2oracle/edit.go:3352— d2oracle._updateImport has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
utf8FontFile.parseHMTXTable (cyclomatic 18) lib/font/subsetFont.go:582— utf8FontFile.parseHMTXTable has cyclomatic complexity 18 (threshold 15). This file's own header attributes it to another copyright holder, so it is code this repository carries rather than code it wrote: restructuring the body in place forks it from upstream and turns every future re-sync into a manual merge. The performable moves are to leave the body as close to its upstream form as possible and keep it behind a narrow interface of your own, and to re-sync it when upstream changes — or, if it has already diverged far enough that you maintain it here, adopt it deliberately and then split the body into named stages.
Graph.IDA (cyclomatic 17) d2graph/d2graph.go:94— Graph.IDA has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Map.createEdge2 (cyclomatic 17) d2ir/d2ir.go:1383— Map.createEdge2 has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2elklayout.adjustPadding (cyclomatic 17) d2layouts/d2elklayout/layout.go:1018— d2elklayout.adjustPadding has cyclomatic complexity 17 (threshold 15). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Where every arm is uniform — the same kind of value, with no behaviour of its own — a table keyed by the case is the shorter form; wherever the arms carry different data or different behaviour, keep them as cases, because collapsing those trades an explicit, reviewable set of cases for nothing.
d2layouts.ExtractSubgraph (cyclomatic 17) d2layouts/d2layouts.go:375— d2layouts.ExtractSubgraph has cyclomatic complexity 17 (threshold 15). Of this number, 16 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2oracle.deleteMapField (cyclomatic 17) d2oracle/edit.go:1419— d2oracle.deleteMapField has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.parseKey (cyclomatic 17) d2parser/parse.go:974— parser.parseKey has cyclomatic complexity 17 (threshold 15). Of this number, 13 points are the body's own statements and 4 belong to one function literal inside it that branches. To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
asciishapes.DrawCallout (cyclomatic 17) d2renderers/d2ascii/asciishapes/callout.go:5— asciishapes.DrawCallout has cyclomatic complexity 17 (threshold 15). To reduce it, separate the branches: extract each independent case into its own named function so the top-level body reads as a short sequence of named decisions.
asciishapes.DrawHex (cyclomatic 17) d2renderers/d2ascii/asciishapes/hexagon.go:7— asciishapes.DrawHex has cyclomatic complexity 17 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
Diagram.GetCorpus (cyclomatic 17) d2target/d2target.go:506— Diagram.GetCorpus has cyclomatic complexity 17 (threshold 15). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
utf8FontFile.GenerateCutFont (cyclomatic 17) lib/font/subsetFont.go:387— utf8FontFile.GenerateCutFont has cyclomatic complexity 17 (threshold 15). This file's own header attributes it to another copyright holder, so it is code this repository carries rather than code it wrote: restructuring the body in place forks it from upstream and turns every future re-sync into a manual merge. The performable moves are to leave the body as close to its upstream form as possible and keep it behind a narrow interface of your own, and to re-sync it when upstream changes — or, if it has already diverged far enough that you maintain it here, adopt it deliberately and then split the body into named stages.
Presentation.SaveTo (cyclomatic 17) lib/pptx/pptx.go:172— Presentation.SaveTo has cyclomatic complexity 17 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Object.Text (cyclomatic 16) d2graph/d2graph.go:661— Object.Text has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
compiler._ampersandPropertyFilter (cyclomatic 16) d2ir/compile.go:962— compiler._ampersandPropertyFilter has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
RefContext.Equal (cyclomatic 16) d2ir/d2ir.go:650— RefContext.Equal has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.getLongestEdgeChainTail (cyclomatic 16) d2layouts/d2dagrelayout/layout.go:479— d2dagrelayout.getLongestEdgeChainTail has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2dagrelayout.positionLabelsIcons (cyclomatic 16) d2layouts/d2dagrelayout/layout.go:546— d2dagrelayout.positionLabelsIcons has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2elklayout.positionLabelsIcons (cyclomatic 16) d2layouts/d2elklayout/layout.go:1110— d2elklayout.positionLabelsIcons has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
d2lsp.GetRefRanges (cyclomatic 16) d2lsp/d2lsp.go:14— d2lsp.GetRefRanges has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.parseValue (cyclomatic 16) d2parser/parse.go:1631— parser.parseValue has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
asciiroute.drawConnectionLabel (cyclomatic 16) d2renderers/d2ascii/asciiroute/labels.go:87— asciiroute.drawConnectionLabel has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
asciishapes.DrawRect (cyclomatic 16) d2renderers/d2ascii/asciishapes/rectangle.go:11— asciishapes.DrawRect has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
GoFPDF.AddPDFPage (cyclomatic 16) lib/pdf/pdf.go:69— GoFPDF.AddPDFPage has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
xgif.AnimatePNGs (cyclomatic 16) lib/xgif/xgif.go:95— xgif.AnimatePNGs has cyclomatic complexity 16 (threshold 15). Most of this is not in the body itself: 6 of the 16 points are its own statements and the rest belongs to one function literal inside it that branches (line 126). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
Hotspot: d2cli/main.go d2cli/main.go— d2cli/main.go changed 3 times in last 90 days, max complexity 89. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, behind tests written first.
d2oracle._set (cognitive 455) d2oracle/edit.go:327— d2oracle._set has cognitive complexity 455 (threshold 15). Drivers by points: if/else 387, loops 26, boolean chains 25, match/switch 17 (nesting depth added 308). Of this number, 445 points are the body's own statements and 10 belong to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.move (cognitive 356) d2oracle/edit.go:1767— d2oracle.move has cognitive complexity 356 (threshold 15). Drivers by points: if/else 297, loops 42, boolean chains 17 (nesting depth added 230). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.shiftReachableDown (cognitive 279) d2layouts/d2dagrelayout/layout.go:765— d2dagrelayout.shiftReachableDown has cognitive complexity 279 (threshold 15). Drivers by points: if/else 214, loops 47, boolean chains 18 (nesting depth added 174). Of this number, 61 points are the body's own statements and 218 belong to 3 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2svg.drawShape (cognitive 268) d2renderers/d2svg/d2svg.go:1602— d2svg.drawShape has cognitive complexity 268 (threshold 15). Drivers by points: if/else 228, loops 26, boolean chains 11, match/switch 3 (nesting depth added 149). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.fitPadding (cognitive 248) d2layouts/d2dagrelayout/layout.go:1339— d2dagrelayout.fitPadding has cognitive complexity 248 (threshold 15). Drivers by points: if/else 172, loops 45, match/switch 22, boolean chains 9 (nesting depth added 166). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Ruler.measureNode (cognitive 205) lib/textmeasure/markdown.go:217— Ruler.measureNode has cognitive complexity 205 (threshold 15). Drivers by points: if/else 154, loops 28, boolean chains 15, match/switch 8 (nesting depth added 122). Of this number, 201 points are the body's own statements and 4 belong to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler._compileEdges (cognitive 190) d2ir/compile.go:1392— compiler._compileEdges has cognitive complexity 190 (threshold 15). Drivers by points: if/else 145, loops 30, boolean chains 15 (nesting depth added 136). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2elklayout.Layout (cognitive 182) d2layouts/d2elklayout/layout.go:154— d2elklayout.Layout has cognitive complexity 182 (threshold 15). Drivers by points: if/else 119, loops 34, boolean chains 17, match/switch 12 (nesting depth added 87). Of this number, 145 points are the body's own statements and 37 belong to 3 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.adjustRankSpacing (cognitive 176) d2layouts/d2dagrelayout/layout.go:1078— d2dagrelayout.adjustRankSpacing has cognitive complexity 176 (threshold 15). Drivers by points: if/else 131, loops 37, boolean chains 8 (nesting depth added 117). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.resolveSubstitutions (cognitive 169) d2ir/compile.go:228— compiler.resolveSubstitutions has cognitive complexity 169 (threshold 15). Drivers by points: if/else 117, loops 33, match/switch 16, boolean chains 3 (nesting depth added 128). The drivers above price the dispatch low by construction — a dispatch is charged once however many cases it lists, while each branch inside an arm is charged in full — so most of this count is what the case bodies hold, and the arms are where it can be reduced. To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
d2svg.Render (cognitive 141) d2renderers/d2svg/d2svg.go:2733— d2svg.Render has cognitive complexity 141 (threshold 15). Drivers by points: if/else 109, loops 18, boolean chains 11, match/switch 3 (nesting depth added 65). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2svg.drawConnection (cognitive 137) d2renderers/d2svg/d2svg.go:1006— d2svg.drawConnection has cognitive complexity 137 (threshold 15). Drivers by points: if/else 118, loops 12, boolean chains 7 (nesting depth added 74). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.updateNear (cognitive 129) d2oracle/edit.go:2330— d2oracle.updateNear has cognitive complexity 129 (threshold 15). Drivers by points: if/else 120, loops 6, boolean chains 3 (nesting depth added 89). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileReserved (cognitive 123) d2compiler/compile.go:537— compiler.compileReserved has cognitive complexity 123 (threshold 15). Drivers by points: if/else 89, match/switch 14, loops 13, boolean chains 7 (nesting depth added 71). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Map.ensureField (cognitive 121) d2ir/d2ir.go:858— Map.ensureField has cognitive complexity 121 (threshold 15). Drivers by points: if/else 101, boolean chains 11, loops 9 (nesting depth added 59). Of this number, 96 points are the body's own statements and 25 belong to 3 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Graph.SetDimensions (cognitive 115) d2graph/d2graph.go:1502— Graph.SetDimensions has cognitive complexity 115 (threshold 15). Drivers by points: if/else 92, boolean chains 15, match/switch 6, loops 2 (nesting depth added 56). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.Layout (cognitive 112) d2layouts/d2dagrelayout/layout.go:72— d2dagrelayout.Layout has cognitive complexity 112 (threshold 15). Drivers by points: if/else 80, loops 20, boolean chains 8, match/switch 4 (nesting depth added 51). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler._compileField (cognitive 109) d2ir/compile.go:1058— compiler._compileField has cognitive complexity 109 (threshold 15). Drivers by points: if/else 74, loops 15, match/switch 13, boolean chains 7 (nesting depth added 61). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli.Run (cognitive 107) d2cli/main.go:52— d2cli.Run has cognitive complexity 107 (threshold 15). Drivers by points: if/else 97, boolean chains 7, match/switch 3 (nesting depth added 23). Of this number, 105 points are the body's own statements and 2 belong to one function literal inside it that branches. To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
d2elklayout.deleteBends (cognitive 107) d2layouts/d2elklayout/layout.go:661— d2elklayout.deleteBends has cognitive complexity 107 (threshold 15). Drivers by points: if/else 95, loops 9, match/switch 3 (nesting depth added 68). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.Delete (cognitive 104) d2oracle/edit.go:938— d2oracle.Delete has cognitive complexity 104 (threshold 15). Drivers by points: if/else 84, loops 19, boolean chains 1 (nesting depth added 61). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2layouts.LayoutNested (cognitive 103) d2layouts/d2layouts.go:78— d2layouts.LayoutNested has cognitive complexity 103 (threshold 15). Drivers by points: if/else 77, loops 21, boolean chains 3, match/switch 2 (nesting depth added 58). Of this number, 100 points are the body's own statements and 3 belong to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.DeleteIDDeltas (cognitive 101) d2oracle/edit.go:2970— d2oracle.DeleteIDDeltas has cognitive complexity 101 (threshold 15). Drivers by points: if/else 73, loops 25, boolean chains 3 (nesting depth added 59). Of this number, 85 points are the body's own statements and 16 belong to 3 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.ampersandFilter (cognitive 96) d2ir/compile.go:718— compiler.ampersandFilter has cognitive complexity 96 (threshold 15). Drivers by points: if/else 60, loops 17, boolean chains 13, match/switch 6 (nesting depth added 47). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Edge.TraceToShape (cognitive 94) d2graph/layout.go:414— Edge.TraceToShape has cognitive complexity 94 (threshold 15). Drivers by points: if/else 68, boolean chains 14, loops 12 (nesting depth added 50). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Style.Apply (cognitive 90) d2graph/d2graph.go:315— Style.Apply has cognitive complexity 90 (threshold 15). Drivers by points: if/else 80, boolean chains 9, match/switch 1 (nesting depth added 40). The drivers above price the dispatch low by construction — a dispatch is charged once however many cases it lists, while each branch inside an arm is charged in full — so most of this count is what the case bodies hold, and the arms are where it can be reduced. To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
d2oracle.renameConflictsToParent (cognitive 90) d2oracle/edit.go:1163— d2oracle.renameConflictsToParent has cognitive complexity 90 (threshold 15). Drivers by points: if/else 67, loops 21, boolean chains 2 (nesting depth added 56). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gridDiagram.layoutDynamic (cognitive 89) d2layouts/d2grid/layout.go:324— gridDiagram.layoutDynamic has cognitive complexity 89 (threshold 15). Drivers by points: loops 67, if/else 22 (nesting depth added 56). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
d2oracle.MoveIDDeltas (cognitive 84) d2oracle/edit.go:2776— d2oracle.MoveIDDeltas has cognitive complexity 84 (threshold 15). Drivers by points: if/else 63, loops 17, boolean chains 4 (nesting depth added 44). Of this number, 69 points are the body's own statements and 15 belong to 3 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2lsp.getKeywordContext (cognitive 83) d2lsp/completion.go:103— d2lsp.getKeywordContext has cognitive complexity 83 (threshold 15). Drivers by points: if/else 71, boolean chains 11, loops 1 (nesting depth added 45). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli.compile (cognitive 77) d2cli/main.go:490— d2cli.compile has cognitive complexity 77 (threshold 15). Drivers by points: if/else 75, boolean chains 1, match/switch 1 (nesting depth added 38). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileMap (cognitive 76) d2ir/compile.go:502— compiler.compileMap has cognitive complexity 76 (threshold 15). Drivers by points: if/else 47, loops 24, boolean chains 3, match/switch 2 (nesting depth added 47). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
main.main (cognitive 76) e2etests/report/main.go:34— main.main has cognitive complexity 76 (threshold 15). Drivers by points: if/else 71, loops 4, boolean chains 1 (nesting depth added 41). Of this number, 30 points are the body's own statements and 46 belong to 2 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.ReconnectEdge (cognitive 72) d2oracle/edit.go:124— d2oracle.ReconnectEdge has cognitive complexity 72 (threshold 15). Drivers by points: if/else 62, boolean chains 7, loops 3 (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseUnquotedString (cognitive 70) d2parser/parse.go:1068— parser.parseUnquotedString has cognitive complexity 70 (threshold 15). Drivers by points: if/else 52, match/switch 12, boolean chains 5, loops 1 (nesting depth added 37). Of this number, 64 points are the body's own statements and 6 belong to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Map.createEdge (cognitive 69) d2ir/d2ir.go:1272— Map.createEdge has cognitive complexity 69 (threshold 15). Drivers by points: if/else 52, loops 13, boolean chains 4 (nesting depth added 37). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2grid.Layout (cognitive 69) d2layouts/d2grid/layout.go:25— d2grid.Layout has cognitive complexity 69 (threshold 15). Drivers by points: if/else 51, boolean chains 11, match/switch 6, loops 1 (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.deleteObject (cognitive 69) d2oracle/edit.go:1525— d2oracle.deleteObject has cognitive complexity 69 (threshold 15). Drivers by points: if/else 54, boolean chains 9, loops 6 (nesting depth added 35). Of this number, 68 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle._updateImport (cognitive 69) d2oracle/edit.go:3352— d2oracle._updateImport has cognitive complexity 69 (threshold 15). Drivers by points: if/else 67, boolean chains 1, loops 1 (nesting depth added 47). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Canvas.ToByteArray (cognitive 68) d2renderers/d2ascii/asciicanvas/asciicanvas.go:76— Canvas.ToByteArray has cognitive complexity 68 (threshold 15). Drivers by points: if/else 43, loops 18, boolean chains 7 (nesting depth added 34). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.validateNear (cognitive 66) d2compiler/compile.go:1170— compiler.validateNear has cognitive complexity 66 (threshold 15). Drivers by points: if/else 54, loops 10, boolean chains 2 (nesting depth added 44). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2elklayout.countEdgeIntersects (cognitive 65) d2layouts/d2elklayout/layout.go:900— d2elklayout.countEdgeIntersects has cognitive complexity 65 (threshold 15). Drivers by points: if/else 62, loops 3 (nesting depth added 50). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Key.Equals (cognitive 62) d2ast/d2ast.go:895— Key.Equals has cognitive complexity 62 (threshold 15). Drivers by points: if/else 50, loops 7, boolean chains 5 (nesting depth added 22). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.shiftDown (cognitive 62) d2layouts/d2dagrelayout/layout.go:633— d2dagrelayout.shiftDown has cognitive complexity 62 (threshold 15). Drivers by points: if/else 44, loops 14, boolean chains 4 (nesting depth added 38). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.shiftUp (cognitive 62) d2layouts/d2dagrelayout/layout.go:697— d2dagrelayout.shiftUp has cognitive complexity 62 (threshold 15). Drivers by points: if/else 44, loops 14, boolean chains 4 (nesting depth added 38). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.deleteReserved (cognitive 62) d2oracle/edit.go:1314— d2oracle.deleteReserved has cognitive complexity 62 (threshold 15). Drivers by points: if/else 56, boolean chains 5, loops 1 (nesting depth added 33). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileField (cognitive 61) d2compiler/compile.go:346— compiler.compileField has cognitive complexity 61 (threshold 15). Drivers by points: if/else 42, boolean chains 11, loops 8 (nesting depth added 26). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2exporter.applyTheme (cognitive 61) d2exporter/export.go:80— d2exporter.applyTheme has cognitive complexity 61 (threshold 15). Drivers by points: if/else 54, boolean chains 7 (nesting depth added 31). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compilePosition (cognitive 60) d2compiler/compile.go:478— compiler.compilePosition has cognitive complexity 60 (threshold 15). Drivers by points: if/else 32, match/switch 25, loops 2, boolean chains 1 (nesting depth added 43). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.adjustCrossRankSpacing (cognitive 60) d2layouts/d2dagrelayout/layout.go:1261— d2dagrelayout.adjustCrossRankSpacing has cognitive complexity 60 (threshold 15). Drivers by points: if/else 43, loops 17 (nesting depth added 38). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileMap (cognitive 59) d2compiler/compile.go:274— compiler.compileMap has cognitive complexity 59 (threshold 15). Drivers by points: if/else 41, loops 14, boolean chains 2, match/switch 2 (nesting depth added 34). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Map.DeleteField (cognitive 58) d2ir/d2ir.go:1089— Map.DeleteField has cognitive complexity 58 (threshold 15). Drivers by points: if/else 29, loops 27, boolean chains 2 (nesting depth added 41). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ASCIIartist.calculateExtendedBounds (cognitive 58) d2renderers/d2ascii/d2ascii.go:140— ASCIIartist.calculateExtendedBounds has cognitive complexity 58 (threshold 15). Drivers by points: if/else 51, loops 4, boolean chains 3 (nesting depth added 36). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Graph.Texts (cognitive 57) d2graph/d2graph.go:1697— Graph.Texts has cognitive complexity 57 (threshold 15). Drivers by points: if/else 27, loops 24, boolean chains 6 (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.IsContainer (cognitive 57) d2ir/d2ir.go:708— compiler.IsContainer has cognitive complexity 57 (threshold 15). Drivers by points: if/else 41, loops 12, boolean chains 4 (nesting depth added 39). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Diagram.BoundingBox (cognitive 57) d2target/d2target.go:277— Diagram.BoundingBox has cognitive complexity 57 (threshold 15). Drivers by points: if/else 49, boolean chains 4, loops 4 (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2graph.CompareSerializedObject (cognitive 56) d2graph/serde.go:211— d2graph.CompareSerializedObject has cognitive complexity 56 (threshold 15). Drivers by points: if/else 43, boolean chains 11, loops 2 (nesting depth added 9). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
d2dagrelayout.adjustDeltaForEdges (cognitive 55) d2layouts/d2dagrelayout/layout.go:1666— d2dagrelayout.adjustDeltaForEdges has cognitive complexity 55 (threshold 15). Drivers by points: if/else 50, boolean chains 4, loops 1 (nesting depth added 23). Of this number, 35 points are the body's own statements and 20 belong to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2exporter.toConnection (cognitive 53) d2exporter/export.go:338— d2exporter.toConnection has cognitive complexity 53 (threshold 15). Drivers by points: if/else 49, boolean chains 3, loops 1 (nesting depth added 12). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
d2svg.arrowheadMarker (cognitive 52) d2renderers/d2svg/d2svg.go:454— d2svg.arrowheadMarker has cognitive complexity 52 (threshold 15). Drivers by points: if/else 48, boolean chains 2, match/switch 2 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Key.D2OracleEquals (cognitive 51) d2ast/d2ast.go:813— Key.D2OracleEquals has cognitive complexity 51 (threshold 15). Drivers by points: if/else 40, loops 6, boolean chains 5 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utf8FontFile.parseHMTXTable (cognitive 49) lib/font/subsetFont.go:582— utf8FontFile.parseHMTXTable has cognitive complexity 49 (threshold 15). Drivers by points: if/else 38, loops 8, boolean chains 3 (nesting depth added 32). This file's own header attributes it to another copyright holder, so it is code this repository carries rather than code it wrote: restructuring the body in place forks it from upstream and turns every future re-sync into a manual merge. The performable moves are to leave the body as close to its upstream form as possible and keep it behind a narrow interface of your own, and to re-sync it when upstream changes — or, if it has already diverged far enough that you maintain it here, adopt it deliberately and then split the body into named stages.
compiler.extendLinks (cognitive 48) d2ir/compile.go:1238— compiler.extendLinks has cognitive complexity 48 (threshold 15). Drivers by points: if/else 36, boolean chains 8, loops 4 (nesting depth added 25). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2svg.dimensions (cognitive 48) d2renderers/d2svg/d2svg.go:99— d2svg.dimensions has cognitive complexity 48 (threshold 15). Drivers by points: if/else 37, loops 6, boolean chains 5 (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Map.getEdges (cognitive 47) d2ir/d2ir.go:1179— Map.getEdges has cognitive complexity 47 (threshold 15). Drivers by points: if/else 34, loops 13 (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.adjustEdges (cognitive 47) d2layouts/d2dagrelayout/layout.go:1756— d2dagrelayout.adjustEdges has cognitive complexity 47 (threshold 15). Drivers by points: if/else 42, boolean chains 4, loops 1 (nesting depth added 22). Most of this is not in the body itself: 5 of the 47 points are its own statements and the rest belongs to one function literal inside it that branches (line 1757). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
ThemableElement.Render (cognitive 47) d2themes/element.go:111— ThemableElement.Render has cognitive complexity 47 (threshold 15). Drivers by points: if/else 46, boolean chains 1 (nesting depth added 6). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
d2oracle.ReconnectEdgeIDDeltas (cognitive 45) d2oracle/edit.go:2502— d2oracle.ReconnectEdgeIDDeltas has cognitive complexity 45 (threshold 15). Drivers by points: if/else 39, boolean chains 4, loops 2 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
watcher.watchLoop (cognitive 44) d2cli/watch.go:225— watcher.watchLoop has cognitive complexity 44 (threshold 15). Drivers by points: if/else 31, loops 10, match/switch 2, boolean chains 1 (nesting depth added 28). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.validateKey (cognitive 44) d2compiler/compile.go:1098— compiler.validateKey has cognitive complexity 44 (threshold 15). Drivers by points: if/else 29, boolean chains 11, match/switch 4 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Object.GetDefaultSize (cognitive 44) d2graph/d2graph.go:995— Object.GetDefaultSize has cognitive complexity 44 (threshold 15). Drivers by points: if/else 37, loops 6, match/switch 1 (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
printer._map (cognitive 43) d2format/format.go:287— printer._map has cognitive complexity 43 (threshold 15). Drivers by points: if/else 34, boolean chains 7, loops 2 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2sequence.newSequenceDiagram (cognitive 43) d2layouts/d2sequence/sequence_diagram.go:77— d2sequence.newSequenceDiagram has cognitive complexity 43 (threshold 15). Drivers by points: if/else 29, loops 11, match/switch 3 (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2plugin.FeatureSupportCheck (cognitive 43) d2plugin/plugin_features.go:27— d2plugin.FeatureSupportCheck has cognitive complexity 43 (threshold 15). Drivers by points: if/else 33, boolean chains 6, loops 4 (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.generateUniqueKey (cognitive 40) d2oracle/edit.go:2648— d2oracle.generateUniqueKey has cognitive complexity 40 (threshold 15). Drivers by points: if/else 32, loops 5, boolean chains 3 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.getLongestEdgeChainHead (cognitive 39) d2layouts/d2dagrelayout/layout.go:414— d2dagrelayout.getLongestEdgeChainHead has cognitive complexity 39 (threshold 15). Drivers by points: if/else 26, loops 10, boolean chains 3 (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseMap (cognitive 39) d2parser/parse.go:386— parser.parseMap has cognitive complexity 39 (threshold 15). Drivers by points: if/else 32, loops 3, boolean chains 2, match/switch 2 (nesting depth added 21). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciishapes.DrawPerson (cognitive 39) d2renderers/d2ascii/asciishapes/person.go:5— asciishapes.DrawPerson has cognitive complexity 39 (threshold 15). Drivers by points: if/else 23, boolean chains 10, loops 3, match/switch 3 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gridDiagram.getBestLayout (cognitive 38) d2layouts/d2grid/layout.go:550— gridDiagram.getBestLayout has cognitive complexity 38 (threshold 15). Drivers by points: if/else 31, boolean chains 4, loops 3 (nesting depth added 7). Of this number, 24 points are the body's own statements and 14 belong to 3 function literals inside it that branch. To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
d2cli.renderPPTX (cognitive 37) d2cli/main.go:1133— d2cli.renderPPTX has cognitive complexity 37 (threshold 15). Drivers by points: if/else 31, loops 5, boolean chains 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2compiler.compileConfig (cognitive 37) d2compiler/compile.go:1505— d2compiler.compileConfig has cognitive complexity 37 (threshold 15). Drivers by points: if/else 18, match/switch 10, loops 7, boolean chains 2 (nesting depth added 17). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
compiler.compileSubstitutions (cognitive 37) d2ir/compile.go:127— compiler.compileSubstitutions has cognitive complexity 37 (threshold 15). Drivers by points: if/else 29, loops 6, boolean chains 2 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
gridDiagram.layoutEvenly (cognitive 37) d2layouts/d2grid/layout.go:232— gridDiagram.layoutEvenly has cognitive complexity 37 (threshold 15). Drivers by points: if/else 19, loops 18 (nesting depth added 18). Of this number, 34 points are the body's own statements and 3 belong to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2near.Layout (cognitive 37) d2layouts/d2near/layout.go:35— d2near.Layout has cognitive complexity 37 (threshold 15). Drivers by points: loops 21, if/else 16 (nesting depth added 24). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
ASCIIartist.Render (cognitive 37) d2renderers/d2ascii/d2ascii.go:222— ASCIIartist.Render has cognitive complexity 37 (threshold 15). Drivers by points: if/else 19, loops 9, match/switch 5, boolean chains 4 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utf8FontFile.GenerateCutFont (cognitive 37) lib/font/subsetFont.go:387— utf8FontFile.GenerateCutFont has cognitive complexity 37 (threshold 15). Drivers by points: if/else 28, loops 8, boolean chains 1 (nesting depth added 19). This file's own header attributes it to another copyright holder, so it is code this repository carries rather than code it wrote: restructuring the body in place forks it from upstream and turns every future re-sync into a manual merge. The performable moves are to leave the body as close to its upstream form as possible and keep it behind a narrow interface of your own, and to re-sync it when upstream changes — or, if it has already diverged far enough that you maintain it here, adopt it deliberately and then split the body into named stages.
Graph.IDA (cognitive 36) d2graph/d2graph.go:94— Graph.IDA has cognitive complexity 36 (threshold 15). Drivers by points: if/else 25, loops 11 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Object.GetFill (cognitive 36) d2graph/d2graph.go:512— Object.GetFill has cognitive complexity 36 (threshold 15). Drivers by points: if/else 29, boolean chains 7 (nesting depth added 6). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
d2oracle.deleteMapField (cognitive 36) d2oracle/edit.go:1419— d2oracle.deleteMapField has cognitive complexity 36 (threshold 15). Drivers by points: if/else 32, boolean chains 3, loops 1 (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciishapes.DrawCylinder (cognitive 36) d2renderers/d2ascii/asciishapes/cylinder.go:3— asciishapes.DrawCylinder has cognitive complexity 36 (threshold 15). Drivers by points: if/else 21, boolean chains 9, loops 3, match/switch 3 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Map.FindBoardRoot (cognitive 35) d2ir/d2ir.go:1937— Map.FindBoardRoot has cognitive complexity 35 (threshold 15). Drivers by points: if/else 26, loops 6, boolean chains 3 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciiroute.drawConnectionLabel (cognitive 35) d2renderers/d2ascii/asciiroute/labels.go:87— asciiroute.drawConnectionLabel has cognitive complexity 35 (threshold 15). Drivers by points: if/else 22, loops 13 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Diagram.GetCorpus (cognitive 35) d2target/d2target.go:506— Diagram.GetCorpus has cognitive complexity 35 (threshold 15). Drivers by points: loops 19, if/else 16 (nesting depth added 18). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
d2cli.loadFonts (cognitive 34) d2cli/main.go:1320— d2cli.loadFonts has cognitive complexity 34 (threshold 15). Drivers by points: if/else 31, boolean chains 3 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Diagram.GetBoard (cognitive 34) d2target/d2target.go:106— Diagram.GetBoard has cognitive complexity 34 (threshold 15). Drivers by points: if/else 23, loops 9, boolean chains 1, match/switch 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli._render (cognitive 33) d2cli/main.go:909— d2cli._render has cognitive complexity 33 (threshold 15). Drivers by points: if/else 29, boolean chains 2, match/switch 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Map.createEdge2 (cognitive 33) d2ir/d2ir.go:1383— Map.createEdge2 has cognitive complexity 33 (threshold 15). Drivers by points: if/else 26, loops 7 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2format.escapeUnquotedValue (cognitive 32) d2format/escape.go:45— d2format.escapeUnquotedValue has cognitive complexity 32 (threshold 15). Drivers by points: if/else 24, match/switch 6, boolean chains 1, loops 1 (nesting depth added 20). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2graph.GetTextDimensionsWithMono (cognitive 32) d2graph/d2graph.go:1441— d2graph.GetTextDimensionsWithMono has cognitive complexity 32 (threshold 15). Drivers by points: if/else 27, loops 3, boolean chains 2 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.getLongestEdgeChainTail (cognitive 32) d2layouts/d2dagrelayout/layout.go:479— d2dagrelayout.getLongestEdgeChainTail has cognitive complexity 32 (threshold 15). Drivers by points: if/else 20, loops 10, boolean chains 2 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2near.boundingBox (cognitive 32) d2layouts/d2near/layout.go:151— d2near.boundingBox has cognitive complexity 32 (threshold 15). Drivers by points: if/else 20, loops 5, boolean chains 4, match/switch 3 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciishapes.DrawStoredData (cognitive 32) d2renderers/d2ascii/asciishapes/stored_data.go:7— asciishapes.DrawStoredData has cognitive complexity 32 (threshold 15). Drivers by points: if/else 20, boolean chains 6, loops 3, match/switch 3 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2ast.RawString (cognitive 31) d2ast/d2ast.go:1563— d2ast.RawString has cognitive complexity 31 (threshold 15). Drivers by points: if/else 23, boolean chains 3, match/switch 3, loops 2 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli.renderPDF (cognitive 31) d2cli/main.go:1021— d2cli.renderPDF has cognitive complexity 31 (threshold 15). Drivers by points: if/else 28, loops 3 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Object.ShiftDescendants (cognitive 31) d2graph/layout.go:103— Object.ShiftDescendants has cognitive complexity 31 (threshold 15). Drivers by points: if/else 20, loops 8, boolean chains 3 (nesting depth added 12). Most of this is not in the body itself: 7 of the 31 points are its own statements and the rest belongs to one function literal inside it that branches (line 119). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
parser.parseKey (cognitive 31) d2parser/parse.go:974— parser.parseKey has cognitive complexity 31 (threshold 15). Drivers by points: if/else 25, boolean chains 3, loops 3 (nesting depth added 14). Of this number, 20 points are the body's own statements and 11 belong to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2svg.RenderLegend (cognitive 31) d2renderers/d2svg/d2svg.go:181— d2svg.RenderLegend has cognitive complexity 31 (threshold 15). Drivers by points: if/else 22, boolean chains 5, loops 4 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2exporter.toPrettyLink (cognitive 30) d2exporter/export.go:294— d2exporter.toPrettyLink has cognitive complexity 30 (threshold 15). Drivers by points: if/else 18, loops 6, match/switch 4, boolean chains 1, jumps 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
printer.mapKey (cognitive 30) d2format/format.go:367— printer.mapKey has cognitive complexity 30 (threshold 15). Drivers by points: if/else 25, boolean chains 3, loops 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
sequenceDiagram.placeGroup (cognitive 30) d2layouts/d2sequence/sequence_diagram.go:245— sequenceDiagram.placeGroup has cognitive complexity 30 (threshold 15). Drivers by points: if/else 17, loops 13 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.filterReserved (cognitive 30) d2oracle/edit.go:2266— d2oracle.filterReserved has cognitive complexity 30 (threshold 15). Drivers by points: if/else 26, boolean chains 2, loops 2 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Segment.GetBounds (cognitive 30) lib/geo/segment.go:81— Segment.GetBounds has cognitive complexity 30 (threshold 15). Drivers by points: if/else 28, boolean chains 1, loops 1 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
sequenceDiagram.placeActors (cognitive 29) d2layouts/d2sequence/sequence_diagram.go:362— sequenceDiagram.placeActors has cognitive complexity 29 (threshold 15). Drivers by points: if/else 27, boolean chains 1, loops 1 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.RenameIDDeltas (cognitive 29) d2oracle/edit.go:3161— d2oracle.RenameIDDeltas has cognitive complexity 29 (threshold 15). Drivers by points: if/else 26, loops 2, boolean chains 1 (nesting depth added 9). Of this number, 20 points are the body's own statements and 9 belong to 3 function literals inside it that branch. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseBlockString (cognitive 29) d2parser/parse.go:1397— parser.parseBlockString has cognitive complexity 29 (threshold 15). Drivers by points: if/else 24, loops 4, boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
geo.cubicRoots (cognitive 29) lib/geo/bezier.go:177— geo.cubicRoots has cognitive complexity 29 (threshold 15). Drivers by points: if/else 19, loops 7, boolean chains 3 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GoFPDF.AddPDFPage (cognitive 29) lib/pdf/pdf.go:69— GoFPDF.AddPDFPage has cognitive complexity 29 (threshold 15). Drivers by points: if/else 23, loops 5, boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.validateConfigs (cognitive 28) d2ir/compile.go:172— compiler.validateConfigs has cognitive complexity 28 (threshold 15). Drivers by points: if/else 23, boolean chains 2, match/switch 2, loops 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2layouts.ExtractSubgraph (cognitive 28) d2layouts/d2layouts.go:375— d2layouts.ExtractSubgraph has cognitive complexity 28 (threshold 15). Drivers by points: if/else 19, loops 7, boolean chains 2 (nesting depth added 8). Of this number, 27 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2lsp.GetRefRanges (cognitive 28) d2lsp/d2lsp.go:14— d2lsp.GetRefRanges has cognitive complexity 28 (threshold 15). Drivers by points: if/else 16, loops 11, boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
watcher.compileLoop (cognitive 27) d2cli/watch.go:414— watcher.compileLoop has cognitive complexity 27 (threshold 15). Drivers by points: if/else 22, boolean chains 2, match/switch 2, loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileArray (cognitive 27) d2ir/compile.go:1571— compiler.compileArray has cognitive complexity 27 (threshold 15). Drivers by points: if/else 21, match/switch 5, loops 1 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileEdgeMap (cognitive 26) d2compiler/compile.go:888— compiler.compileEdgeMap has cognitive complexity 26 (threshold 15). Drivers by points: if/else 18, loops 7, boolean chains 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.validatePositionsCompatibility (cognitive 26) d2compiler/compile.go:1243— compiler.validatePositionsCompatibility has cognitive complexity 26 (threshold 15). Drivers by points: if/else 22, loops 3, boolean chains 1 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
xgif.AnimatePNGs (cognitive 26) lib/xgif/xgif.go:95— xgif.AnimatePNGs has cognitive complexity 26 (threshold 15). Drivers by points: if/else 18, loops 7, boolean chains 1 (nesting depth added 11). Most of this is not in the body itself: 6 of the 26 points are its own statements and the rest belongs to one function literal inside it that branches (line 126). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
d2cli.fmtCmd (cognitive 25) d2cli/fmt.go:18— d2cli.fmtCmd has cognitive complexity 25 (threshold 15). Drivers by points: if/else 23, boolean chains 1, loops 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli.render (cognitive 25) d2cli/main.go:813— d2cli.render has cognitive complexity 25 (threshold 15). Drivers by points: if/else 18, boolean chains 4, loops 3 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Map.QueryAll (cognitive 25) d2ir/query.go:10— Map.QueryAll has cognitive complexity 25 (threshold 15). Drivers by points: if/else 20, loops 5 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.getRanks (cognitive 25) d2layouts/d2dagrelayout/layout.go:580— d2dagrelayout.getRanks has cognitive complexity 25 (threshold 15). Drivers by points: if/else 14, loops 8, boolean chains 3 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
sequenceDiagram.adjustGroupLabel (cognitive 25) d2layouts/d2sequence/sequence_diagram.go:312— sequenceDiagram.adjustGroupLabel has cognitive complexity 25 (threshold 15). Drivers by points: if/else 14, loops 9, boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli.resolveLinks (cognitive 24) d2cli/main.go:706— d2cli.resolveLinks has cognitive complexity 24 (threshold 15). Drivers by points: if/else 11, loops 9, boolean chains 4 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli.relink (cognitive 24) d2cli/main.go:777— d2cli.relink has cognitive complexity 24 (threshold 15). Drivers by points: if/else 17, loops 7 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.preprocessEdgeGroup (cognitive 24) d2compiler/compile.go:1394— compiler.preprocessEdgeGroup has cognitive complexity 24 (threshold 15). Drivers by points: if/else 16, loops 8 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2graph.ResolveUnderscoreKey (cognitive 24) d2graph/d2graph.go:779— d2graph.ResolveUnderscoreKey has cognitive complexity 24 (threshold 15). Drivers by points: if/else 18, loops 4, boolean chains 2 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2dagrelayout.positionLabelsIcons (cognitive 24) d2layouts/d2dagrelayout/layout.go:546— d2dagrelayout.positionLabelsIcons has cognitive complexity 24 (threshold 15). Drivers by points: if/else 20, boolean chains 4 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2elklayout.positionLabelsIcons (cognitive 24) d2layouts/d2elklayout/layout.go:1110— d2elklayout.positionLabelsIcons has cognitive complexity 24 (threshold 15). Drivers by points: if/else 20, boolean chains 4 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2grid.layoutGrid (cognitive 24) d2layouts/d2grid/layout.go:186— d2grid.layoutGrid has cognitive complexity 24 (threshold 15). Drivers by points: if/else 20, boolean chains 3, loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
sequenceDiagram.placeSpans (cognitive 24) d2layouts/d2sequence/sequence_diagram.go:517— sequenceDiagram.placeSpans has cognitive complexity 24 (threshold 15). Drivers by points: if/else 16, boolean chains 4, loops 4 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2lsp.getBoardPathAtPosition (cognitive 24) d2lsp/d2lsp.go:107— d2lsp.getBoardPathAtPosition has cognitive complexity 24 (threshold 15). Drivers by points: if/else 20, boolean chains 3, loops 1 (nesting depth added 11). Of this number, 23 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.ensureNode (cognitive 24) d2oracle/edit.go:1654— d2oracle.ensureNode has cognitive complexity 24 (threshold 15). Drivers by points: if/else 18, boolean chains 3, loops 3 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseDoubleQuotedString (cognitive 24) d2parser/parse.go:1264— parser.parseDoubleQuotedString has cognitive complexity 24 (threshold 15). Drivers by points: if/else 22, boolean chains 1, loops 1 (nesting depth added 12). Of this number, 23 points are the body's own statements and 1 belongs to one function literal inside it that branches. To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2sketch.Arrowheads (cognitive 24) d2renderers/d2sketch/sketch.go:930— d2sketch.Arrowheads has cognitive complexity 24 (threshold 15). Drivers by points: if/else 20, loops 4 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2svg.addAppendixItems (cognitive 24) d2renderers/d2svg/d2svg.go:2223— d2svg.addAppendixItems has cognitive complexity 24 (threshold 15). Drivers by points: if/else 20, boolean chains 2, match/switch 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
utf8FontFile.generateSCCSDictionaries (cognitive 24) lib/font/subsetFont.go:672— utf8FontFile.generateSCCSDictionaries has cognitive complexity 24 (threshold 15). Drivers by points: if/else 17, loops 7 (nesting depth added 12). This file's own header attributes it to another copyright holder, so it is code this repository carries rather than code it wrote: restructuring the body in place forks it from upstream and turns every future re-sync into a manual merge. The performable moves are to leave the body as close to its upstream form as possible and keep it behind a narrow interface of your own, and to re-sync it when upstream changes — or, if it has already diverged far enough that you maintain it here, adopt it deliberately and then split the body into named stages.
pptx.Validate (cognitive 24) lib/pptx/validate.go:13— pptx.Validate has cognitive complexity 24 (threshold 15). Drivers by points: if/else 22, loops 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileClass (cognitive 23) d2compiler/compile.go:1000— compiler.compileClass has cognitive complexity 23 (threshold 15). Drivers by points: if/else 14, loops 4, match/switch 3, boolean chains 2 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2graph.addSQLTableColumnIndices (cognitive 22) d2graph/d2graph.go:1347— d2graph.addSQLTableColumnIndices has cognitive complexity 22 (threshold 15). Drivers by points: if/else 16, loops 6 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2graph.CompareSerializedEdge (cognitive 22) d2graph/serde.go:357— d2graph.CompareSerializedEdge has cognitive complexity 22 (threshold 15). Drivers by points: if/else 18, boolean chains 4 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
compiler.ampersandFilterMap (cognitive 22) d2ir/compile.go:465— compiler.ampersandFilterMap has cognitive complexity 22 (threshold 15). Drivers by points: if/else 19, match/switch 2, loops 1 (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2grid.newGridDiagram (cognitive 22) d2layouts/d2grid/grid_diagram.go:28— d2grid.newGridDiagram has cognitive complexity 22 (threshold 15). Drivers by points: if/else 18, loops 3, boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
sequenceDiagram.routeMessages (cognitive 22) d2layouts/d2sequence/sequence_diagram.go:582— sequenceDiagram.routeMessages has cognitive complexity 22 (threshold 15). Drivers by points: if/else 14, loops 7, boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.deleteObjField (cognitive 22) d2oracle/edit.go:1478— d2oracle.deleteObjField has cognitive complexity 22 (threshold 15). Drivers by points: if/else 17, boolean chains 4, loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciishapes.DrawDocument (cognitive 22) d2renderers/d2ascii/asciishapes/document.go:5— asciishapes.DrawDocument has cognitive complexity 22 (threshold 15). Drivers by points: if/else 13, boolean chains 5, loops 4 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
dslGenState.edge (cognitive 21) d2chaos/d2chaos.go:127— dslGenState.edge has cognitive complexity 21 (threshold 15). Drivers by points: if/else 19, boolean chains 1, loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2cli.renderPNGsForGIF (cognitive 21) d2cli/main.go:1435— d2cli.renderPNGsForGIF has cognitive complexity 21 (threshold 15). Drivers by points: if/else 18, loops 3 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
watcher.replaceWatchList (cognitive 21) d2cli/watch.go:377— watcher.replaceWatchList has cognitive complexity 21 (threshold 15). Drivers by points: if/else 15, loops 6 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileArrowheads (cognitive 21) d2compiler/compile.go:948— compiler.compileArrowheads has cognitive complexity 21 (threshold 15). Drivers by points: if/else 17, boolean chains 2, loops 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2exporter.toShape (cognitive 21) d2exporter/export.go:209— d2exporter.toShape has cognitive complexity 21 (threshold 15). Drivers by points: if/else 19, boolean chains 1, match/switch 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
printer.array (cognitive 21) d2format/format.go:245— printer.array has cognitive complexity 21 (threshold 15). Drivers by points: if/else 17, boolean chains 3, loops 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Object.EnsureChild (cognitive 21) d2graph/d2graph.go:875— Object.EnsureChild has cognitive complexity 21 (threshold 15). Drivers by points: if/else 15, boolean chains 4, loops 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Object.GetLabelSize (cognitive 21) d2graph/d2graph.go:944— Object.GetLabelSize has cognitive complexity 21 (threshold 15). Drivers by points: if/else 18, boolean chains 2, match/switch 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler._ampersandPropertyFilter (cognitive 21) d2ir/compile.go:962— compiler._ampersandPropertyFilter has cognitive complexity 21 (threshold 15). Drivers by points: if/else 14, loops 4, boolean chains 2, match/switch 1 (nesting depth added 9). The drivers above price the dispatch low by construction — a dispatch is charged once however many cases it lists, while each branch inside an arm is charged in full — so most of this count is what the case bodies hold, and the arms are where it can be reduced. To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
d2oracle.getMostNestedRefs (cognitive 21) d2oracle/edit.go:3278— d2oracle.getMostNestedRefs has cognitive complexity 21 (threshold 15). Drivers by points: if/else 18, loops 3 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.replaceBoardNodeInMap (cognitive 21) d2oracle/get.go:56— d2oracle.replaceBoardNodeInMap has cognitive complexity 21 (threshold 15). Drivers by points: if/else 15, loops 4, boolean chains 2 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseArray (cognitive 21) d2parser/parse.go:1510— parser.parseArray has cognitive complexity 21 (threshold 15). Drivers by points: if/else 15, loops 3, match/switch 2, boolean chains 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
execPlugin.HydrateOpts (cognitive 21) d2plugin/exec.go:73— execPlugin.HydrateOpts has cognitive complexity 21 (threshold 15). Drivers by points: loops 10, match/switch 8, if/else 3 (nesting depth added 14). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
d2svg.singleThemeRulesets (cognitive 21) d2renderers/d2svg/d2svg.go:3142— d2svg.singleThemeRulesets has cognitive complexity 21 (threshold 15). Drivers by points: if/else 20, loops 1. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
d2compiler.hasBoard (cognitive 20) d2compiler/compile.go:1339— d2compiler.hasBoard has cognitive complexity 20 (threshold 15). Drivers by points: if/else 12, loops 6, boolean chains 1, match/switch 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2exporter.Export (cognitive 20) d2exporter/export.go:22— d2exporter.Export has cognitive complexity 20 (threshold 15). Drivers by points: if/else 11, loops 8, boolean chains 1 (nesting depth added 6). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
d2near.place (cognitive 20) d2layouts/d2near/layout.go:95— d2near.place has cognitive complexity 20 (threshold 15). Drivers by points: if/else 18, boolean chains 1, match/switch 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2lib.compile (cognitive 20) d2lib/d2.go:97— d2lib.compile has cognitive complexity 20 (threshold 15). Drivers by points: if/else 17, loops 3 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Theme.ApplyOverrides (cognitive 20) d2themes/d2themes.go:33— Theme.ApplyOverrides has cognitive complexity 20 (threshold 15). Drivers by points: if/else 20. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Presentation.SaveTo (cognitive 20) lib/pptx/pptx.go:172— Presentation.SaveTo has cognitive complexity 20 (threshold 15). Drivers by points: if/else 17, loops 3 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
onmessage (cognitive 20) d2cli/static/watch.js:18— onmessage has cognitive complexity 20 (threshold 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.validateEdges (cognitive 19) d2compiler/compile.go:1263— compiler.validateEdges has cognitive complexity 19 (threshold 15). Drivers by points: if/else 12, boolean chains 6, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
printer.blockString (cognitive 19) d2format/format.go:159— printer.blockString has cognitive complexity 19 (threshold 15). Drivers by points: if/else 16, loops 3 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
compiler.compileLink (cognitive 19) d2ir/compile.go:1305— compiler.compileLink has cognitive complexity 19 (threshold 15). Drivers by points: if/else 12, boolean chains 5, loops 2 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.Rename (cognitive 19) d2oracle/edit.go:1701— d2oracle.Rename has cognitive complexity 19 (threshold 15). Drivers by points: if/else 18, boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2oracle.GetBoardGraph (cognitive 19) d2oracle/get.go:12— d2oracle.GetBoardGraph has cognitive complexity 19 (threshold 15). Drivers by points: if/else 16, loops 3 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseEdgeIndex (cognitive 19) d2parser/parse.go:827— parser.parseEdgeIndex has cognitive complexity 19 (threshold 15). Drivers by points: if/else 14, boolean chains 3, loops 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseEdges (cognitive 19) d2parser/parse.go:884— parser.parseEdges has cognitive complexity 19 (threshold 15). Drivers by points: if/else 17, boolean chains 1, loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseSingleQuotedString (cognitive 19) d2parser/parse.go:1335— parser.parseSingleQuotedString has cognitive complexity 19 (threshold 15). Drivers by points: if/else 16, match/switch 2, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciiroute.adjustRouteStartPoint (cognitive 19) d2renderers/d2ascii/asciiroute/routing.go:180— asciiroute.adjustRouteStartPoint has cognitive complexity 19 (threshold 15). Drivers by points: if/else 16, loops 3 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciiroute.adjustRouteEndPoint (cognitive 19) d2renderers/d2ascii/asciiroute/routing.go:248— asciiroute.adjustRouteEndPoint has cognitive complexity 19 (threshold 15). Drivers by points: if/else 16, loops 3 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciishapes.DrawQueue (cognitive 19) d2renderers/d2ascii/asciishapes/queue.go:3— asciishapes.DrawQueue has cognitive complexity 19 (threshold 15). Drivers by points: boolean chains 13, loops 3, match/switch 3 (nesting depth added 3). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
asciishapes.DrawRect (cognitive 19) d2renderers/d2ascii/asciishapes/rectangle.go:11— asciishapes.DrawRect has cognitive complexity 19 (threshold 15). Drivers by points: if/else 11, boolean chains 5, loops 3 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciishapes.DrawStep (cognitive 19) d2renderers/d2ascii/asciishapes/step.go:3— asciishapes.DrawStep has cognitive complexity 19 (threshold 15). Drivers by points: boolean chains 8, if/else 8, loops 3 (nesting depth added 3). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Ruler.scaleUnicode (cognitive 19) lib/textmeasure/textmeasure.go:185— Ruler.scaleUnicode has cognitive complexity 19 (threshold 15). Drivers by points: if/else 10, loops 9 (nesting depth added 13). This file's own header attributes it to another copyright holder, so it is code this repository carries rather than code it wrote: restructuring the body in place forks it from upstream and turns every future re-sync into a manual merge. The performable moves are to leave the body as close to its upstream form as possible and keep it behind a narrow interface of your own, and to re-sync it when upstream changes — or, if it has already diverged far enough that you maintain it here, adopt it deliberately and then split the body into named stages.
xgif.ConvertAnimatedSVGToPNGs (cognitive 19) lib/xgif/xgif.go:37— xgif.ConvertAnimatedSVGToPNGs has cognitive complexity 19 (threshold 15). Drivers by points: if/else 16, loops 3 (nesting depth added 10). Most of this is not in the body itself: 2 of the 19 points are its own statements and the rest belongs to one function literal inside it that branches (line 48). The decisions are inside the literal, which nothing outside this body can call, review or test on its own, so splitting the enclosing body is not the move available here. To reduce it, lift the literal's work into a named function or method at the enclosing scope and have the literal call it, then reduce whichever part then reads as the largest.
compiler.validateBoardLinks (cognitive 18) d2compiler/compile.go:1296— compiler.validateBoardLinks has cognitive complexity 18 (threshold 15). Drivers by points: if/else 12, loops 4, boolean chains 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
d2exporter.applyStyles (cognitive 18) d2exporter/export.go:152— d2exporter.applyStyles has cognitive complexity 18 (threshold 15). Drivers by points: if/else 18. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Object.GetMargin (cognitive 18) d2graph/layout.go:289— Object.GetMargin has cognitive complexity 18 (threshold 15). Drivers by points: match/switch 10, if/else 6, boolean chains 2 (nesting depth added 8). To reduce it, keep the dispatch but shrink the arms: move each non-trivial case body into its own named function (or onto the value being matched) so the dispatch reads one line per case, and group related cases into a sub-dispatch. Keep every case explicit, and make the behaviour for cases you do not list a deliberate choice rather than an accident.
d2oracle.bumpChildrenUnderscores (cognitive 18) d2oracle/edit.go:1108— d2oracle.bumpChildrenUnderscores has cognitive complexity 18 (threshold 15). Drivers by points: if/else 15, loops 3 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.parseArrayNode (cognitive 18) d2parser/parse.go:1566— parser.parseArrayNode has cognitive complexity 18 (threshold 15). Drivers by points: if/else 15, boolean chains 2, match/switch 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
asciiroute.shouldDrawTJunction (cognitive 18) d2renderers/d2ascii/asciiroute/drawing.go:223— asciiroute.shouldDrawTJunction has cognitive complexity 18 (threshold 15). Drivers by points: if/else 10, boolean chains 8 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Machine-readable and reproducible from this commit + frozen rubric — drop them straight into a contract appendix, a CRA dossier, or a downstream SCA / VEX tool.