Skip to content

docs: fix stale and incorrect code comments across the package - #12

Open
eonist wants to merge 1 commit into
fix/safe-hardening-and-platform-floorfrom
docs/comment-audit-fixes
Open

eonist wants to merge 1 commit into
fix/safe-hardening-and-platform-floorfrom
docs/comment-audit-fixes

Conversation

@eonist

@eonist eonist commented Aug 28, 2026

Copy link
Copy Markdown
Member

Resolves the audit in #11.

Every changed line in this PR is a comment. The only non-comment line in the diff gains a trailing comment; nothing else moves. All 17 tests pass, build is clean with no warnings.

Note

Stacked on #9, so this PR targets fix/safe-hardening-and-platform-floor rather than main. Three of the fixes (the macOS 13 floor references) only make sense on top of that branch. Retarget to main once #9 merges.

What changed

Nine false claims corrected

Comment Was Actually
BlockParser type doc "Top-level only — list-item children are handled recursively inside MarkdownListView" parse recurses into itself; MarkdownListView never calls it
MarkdownListView type doc "nested lists via listDepth" the property is depth; listDepth is the outgoing argument label
MarkdownStyle.textPrimary "headings and body content" table cells only
MarkdownStyle.radiusSmall "inline code chips and code block containers" code block container only
MarkdownStyle.init "Use MarkdownStyle.runBot… rather than constructing a value directly" that symbol does not exist in this package
MarkdownCodeBlockView.language "Lowercased language identifier" passed through verbatim
MarkdownCodeBlockView / MarkdownHighlighter returns nil on "unknown language" unknown languages are auto-detected, never nil
InlineTextView type doc design justified by a macOS 26 deprecation floor is macOS 13; the real reason is per-run intents
MarkdownRenderLog "Internal diagnostics" both renderLogKind extensions are public API
MarkdownTableView "Cell widths are bounded at 220pt" the 220 is in MarkdownTableCellView
MarkdownDetectorTests case 2 credited to the cubic bypass clears the density floor on its own

Verified, not assumed

Three of those were checked by running the code rather than reading it:

BlockParser recursion — parsing - outer / - inner / - deepest yields a model 3 levels deep; 40 nested > markers yield 40. Both built entirely inside BlockParser.parse.

Fence-language casing — #11 §3.6 left this open as a behaviour decision. Resolved as a doc fix, because "SWIFT", "Swift" and "swift" produce byte-identical highlighted output; highlight.js matches case-insensitively. No code change was needed.

That probe also turned up a finding the audit missed: "bogus-lang" does not return nil — it comes back with 6 coloured runs, distinct from both plaintext and swift. highlight.js auto-detects when it doesn't recognise a name. So two comments promising a nil-on-unknown-language path were describing a branch that is never taken, and the ?? "plaintext" fallback in both call sites turns out to be load-bearing: it's what stops untagged output from being auto-detected as some guessed syntax. Both now say so.

Detector boundary case 2 — against the running detector:

case2 shortDense:  score=5 lines=15  density=0.333 (>=0.10: true)   cubic=8.33
case4 mediumPass:  score=7 lines=134 density=0.052 (>=0.10: false)  cubic=2.56

Case 2 passes on density; it does not isolate the cubic bypass the comment credited. Case 4 is the only one of the six that does — and it now says "retune the cubic constant and this is the case that moves."

Provenance and dead references removed

20 file headers naming RunBot, ten comments describing RunBot internals, five issue numbers from another tracker (#2379, #2394, #2600, #2731, #2740), and four symbols that live elsewhere (cleanLogText, StepLogView.loadLog(), MarkdownLogView, MarkdownStyle+RunBot.swift). Also "Option A" and "per repository policy", neither of which named anything findable in this repo.

Each comment's rule was kept; only its RunBot instance was dropped. The ANSI-stripping precondition on MarkdownDetector, for instance, is a real contract the package can't enforce, so it stays — minus the migration plan for another repo's refactor.

Review directives removed from public API docs

Two doc comments addressed a code reviewer, and both shipped in DocC and Xcode Quick Help:

  • "This is NOT a bug in the detector… Do not flag this as a double-parse in the detector itself."
  • "Do not remove it as dead code without explicitly changing that contract."

Both now state the underlying fact for a caller instead. Relatedly, the auto-enable gate was described in three places in MarkdownDetector — which is how one of them drifted, and how DetectResult's copy came to omit the score >= 3 floor. detect(_:) is now the single description; the other two point at it.

Comments added where behaviour is surprising

  • MarkdownCodeBlockView ↔ HighlightPrewarmer — both compute the cache-key language independently. The cache key holds the raw string, so any divergence makes every prewarmed entry miss and silently turns prewarming into an expensive no-op. Both sites now say to keep them identical.
  • BlockParser.parse — recursion depth is bounded only by input, and a Task's cooperative stack is much smaller than the main thread's, so parseAsync overflows shallower. This is the warning that the old "top-level only" comment displaced.
  • parseAsync — does not check Task.isCancelled, though DESIGN.md asks callers to respect cancellation. Now stated, matching how preWarmHighlighter already documents its own behaviour.
  • Inert links — the accent colour is applied outside the scheme guard, so a rejected javascript: link looks exactly like a working one. Marked as the deliberate trade-off it is.
  • Clear underline — AttributedString auto-underlines .link runs with no way to disable it, so the underline is drawn in clear. Reads like a mistake without the note.
  • parseCells — pads short rows and silently drops cells past the delimiter width. Only the padding direction was documented or tested.
  • Three Color(nsColor:) defaults — with import AppKit, the entire iOS blocker.
  • Package.swift — macOS 13 is set by SwiftUI Grid; v12 fails on that symbol alone.

Boilerplate removed

Six identical /// SwiftUI view body — see type-level doc for rendering contract. comments, on views whose type docs mostly had no contract to see. Deleted, and the type docs they pointed at now state one — MarkdownListView explains how nesting is actually resolved, MarkdownTableCellView explains the width cap.

Deliberately not done

Refs #11

Resolves the audit in #11. Every changed line is a comment; no behaviour
changes.

Corrects claims that were false against the code:

- BlockParser was documented as "top-level only", with recursion attributed
  to MarkdownListView. It recurses into lists and block quotes itself, and
  MarkdownListView never calls it. Verified: nested bullets produce a model
  3 levels deep, 40 nested block quotes produce 40. The replacement carries
  the unbounded-depth warning, since this is where the crash in #8 lives.
- MarkdownListView documented a `listDepth` property it does not have.
- MarkdownStyle.textPrimary claimed headings and body text; only table
  cells use it. radiusSmall claimed inline code chips; only the code block
  container uses it.
- The MarkdownStyle initializer told adopters to use `MarkdownStyle.runBot`,
  which does not exist in this package.
- MarkdownCodeBlockView.language claimed a lowercased identifier. Nothing
  lowercases it. Verified that highlight.js matches case-insensitively, so
  the doc was fixed rather than the code.
- MarkdownCodeBlockView and MarkdownHighlighter both claimed an unknown
  language yields nil. Verified it does not — highlight.js auto-detects.
- InlineTextView justified its AttributedString design by a macOS 26
  deprecation; the floor is macOS 13.
- MarkdownRenderLog was described as internal while exporting public API.
- MarkdownTableView documented a 220 pt cap defined in another file.
- A detector boundary case credited the cubic bypass for a pass that
  clears the density floor on its own (5/15 = 0.333). Case 4 is the only
  one that isolates the bypass; both now say so.

Removes references that cannot be resolved from this repository: 20 file
headers naming RunBot, ten comments describing RunBot internals, five
issue numbers from another tracker, and four symbols that live elsewhere.
Two doc comments addressed a code reviewer rather than a caller and shipped
in DocC; both now state the underlying fact instead.

Adds comments where behaviour is genuinely surprising: the coupled
"plaintext" fallback shared by MarkdownCodeBlockView and HighlightPrewarmer,
where divergence would silently make prewarming a no-op; links that keep
accent colour while being inert; the clear-underline workaround; silent cell
truncation in MarkdownTableModel; the three AppKit defaults that make the
package macOS-only; and what pins the macOS 13 floor.

Deletes six identical "see type-level doc for rendering contract" body
comments and gives the types they pointed at an actual contract.

Refs #11
@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Greptile Summary

This documentation-only PR corrects stale or inaccurate comments, removes product-specific provenance, and documents several non-obvious parser, highlighter, rendering, and platform constraints.

  • Aligns public API documentation with current parsing, detection, styling, table, and highlighting behavior.
  • Replaces external product and issue references with package-local contracts and rationale.
  • Adds maintenance warnings around recursive parsing, cancellation, cache-key consistency, safe links, table normalization, and macOS availability.

Confidence Score: 5/5

The PR appears safe to merge because it changes comments only and no concrete inaccurate or behavior-affecting change remains.

The updated documentation is consistent with the inspected parsing, rendering, detection, styling, table, and highlighting paths, with no accepted blocking or non-blocking findings.

Important Files Changed

Filename Overview
Package.swift Documents the macOS 13 deployment floor and rationale for revision-pinned dependencies without changing package configuration.
Sources/MarkdownKit/MarkdownDocumentView.swift Corrects parser recursion documentation and records cancellation and deep-input stack limitations.
Sources/MarkdownKit/Highlighting/MarkdownHighlighter.swift Clarifies unknown-language auto-detection, failure fallback, and bounded-cache behavior.
Sources/MarkdownKit/Rendering/MarkdownCodeBlockView.swift Documents verbatim language handling, plaintext fallback selection, and cache-key alignment with prewarming.
Sources/MarkdownKit/Rendering/MarkdownInlineRenderer.swift Clarifies attributed-text intent handling, safe link activation, and underline suppression.
Sources/MarkdownKit/Styling/MarkdownStyle.swift Corrects token usage documentation and identifies the AppKit-derived color defaults relevant to portability.
Sources/MarkdownKit/Model/MarkdownTableModel.swift Documents delimiter-defined table width and silent normalization of ragged rows.
Tests/MarkdownKitTests/MarkdownDetectorTests.swift Corrects comments identifying which detector boundary case uniquely exercises the cubic bypass.

Reviews (1): Last reviewed commit: "docs: fix stale and incorrect code comme..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant