Skip to content

Don't render broken links to symbols excluded from documentation (#4448) - #4536

Draft
vmishenev wants to merge 2 commits into
masterfrom
vmishenev/4448-fix-broken-links-to-excluded-classes
Draft

Don't render broken links to symbols excluded from documentation (#4448)#4536
vmishenev wants to merge 2 commits into
masterfrom
vmishenev/4448-fix-broken-links-to-excluded-classes

Conversation

@vmishenev

Copy link
Copy Markdown
Contributor

Summary

Fixes #4448.

When a KDoc/signature link references a symbol that is not part of the rendered documentation (suppressed via perPackageOption/suppress, hidden by skipDeprecated, internal, a private constructor, or an undocumented external symbol), the link resolves to a valid DRI during analysis but the target page is never generated. Dokka silently produced a link to a non-existent page and emitted no warning.

Changes

  • Don't render broken links. DefaultExternalModuleLinkResolver.resolve() resolved links purely from a module's package-list, and only verified the target page existed when several local modules shared a package name (the Generating external link should depend on the module it refers to #3368 hack). It now always verifies the page exists — dropping the #anchor first so member links (index.html#anchor) aren't falsely rejected. A missing page yields an unresolved span instead of a dead <a href>.
  • Warn developers. Both the multi-module assembly (ResolveLinkCommandHandler) and single-module rendering (HtmlRenderer.buildDRILink) now log a warning when a documentation link cannot be resolved to a page. Assembly-phase warnings are log-only (so multi-module builds aren't broken by unavoidable external links); single-module warnings flow through each module's own failOnWarning.

Tests

  • New LinkToExcludedSymbolTest (plugin-base): a public symbol linking to an internal one renders an unresolved span (not <a>), logs a warning, and throws under failOnWarning. Passes on K1 and K2.
  • Updated ResolveLinkCommandResolutionTest (+ a negative test where the package resolves but the page is absent) and ResolveLinkGfmCommandResolutionTest for the new existence check.
  • IoGradleIntegrationTest: re-enabled assertNoHrefToMissingLocalFileOrDirectory — now passes (kotlinx-io's broken <init> link became a span, and the new "Couldn't resolve link" warnings appear for its external Apple/stdlib links).

Note for reviewers

AbstractIntegrationTest.assertNoUnresolvedLinks is left as-is. Its regex data-unresolved-link="\[ expects a leading [, but real DRI.toString() values (e.g. platform.Foundation/NSData///…) have none, so it currently matches nothing. Fixing it would fail on kotlinx-io's legitimate external-only spans (Apple platform.Foundation.*, kotlin.Throwable members), so it needs a separate decision (allowlist external packages, or drop the assertion).

🤖 Generated with Claude Code

@vmishenev
vmishenev marked this pull request as draft June 18, 2026 10:56
vmishenev and others added 2 commits June 18, 2026 15:08
When a KDoc/signature link references a symbol that is not part of the
rendered documentation (suppressed via `perPackageOption`/`suppress`,
hidden by `skipDeprecated`, `internal`, a private constructor, or an
undocumented external symbol), the link resolves to a valid DRI during
analysis but the target page is never generated. Dokka silently produced
a link to a non-existent page and emitted no warning.

`DefaultExternalModuleLinkResolver.resolve()` resolved links purely from
a module's package-list, and only verified the target page existed when
several modules shared a package name (the #3368 hack). It now always
verifies the page exists (dropping the `#anchor` first so member links
are not falsely rejected); a missing page yields an unresolved span
instead of a dead `<a href>`.

In addition, both the multi-module assembly (`ResolveLinkCommandHandler`)
and single-module rendering (`HtmlRenderer.buildDRILink`) now warn when a
documentation link cannot be resolved to a page.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vmishenev
vmishenev force-pushed the vmishenev/4448-fix-broken-links-to-excluded-classes branch from a76b0ec to 3d5f762 Compare June 18, 2026 12:41
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.

Dokka should not generate links (and warn about it) to classes excluded from rendered documentation

1 participant