Skip to content

Fix orphaned-block tag bleed and silent NAMESPACE directive drops#19

Merged
TroyHernandez merged 3 commits into
mainfrom
fix/block-merging-and-namespace-drops
Jun 12, 2026
Merged

Fix orphaned-block tag bleed and silent NAMESPACE directive drops#19
TroyHernandez merged 3 commits into
mainfrom
fix/block-merging-and-namespace-drops

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

Fixes #17, fixes #18.

Both issues turned out to be the same class: document() rewriting NAMESPACE more aggressively than the tags imply, silently.

#18 root cause was not @nord handling (a clean @nord block was already correct). parse_file() merged #' runs separated by blank lines or plain comments into one block. So an orphaned block whose function had been moved or deleted bled its @export into the next block:

#' Generate speech in chunks   <- orphaned, its function moved away
#' @export

#' Split text into chunks
#' @noRd
.split_text_chunks <- function(text) ...

parsed as one block with both @export and @nord, giving export(.split_text_chunks) and no Rd. This is exactly what happened in chatterbox's tts.R. Blocks are now strictly consecutive #' lines (roxygen2 semantics), and an orphaned block warns instead of being silently dropped. Plain # comments between a block and its function still attach (also roxygen2 semantics; previously the block was silently lost).

#17: the @useDynLib tag has worked since January (#' @useDynLib pkg, .registration = TRUE above a NULL), but a hand-maintained useDynLib line in NAMESPACE was wiped on every document() run with no signal, and an orphaned tag attempt (e.g. at end of file) failed silently too. Now: write_namespace() warns with the exact dropped lines and the tag to use, and the orphan warning from the #18 fix covers the failed-placement case. export()/S3method() churn is exempt from the warning.

Also in this PR: cran.R's #' file header demoted to plain comments (under the new attachment rules it would document WEBSERVICE_PACKAGES), and four internal functions gained the missing @param pkg_generics that warned on every document() run.

Tests: 173 pass, including new regression tests for the merge bleed, comment-tolerant attachment, orphan warnings, and the directive-drop warning.

…ectives

Two fixes for document() rewriting NAMESPACE more aggressively than
the tags imply:

- parse_file() grouped #' runs separated by blank lines or plain
  comments into one block, so an orphaned block's @export (its function
  moved or deleted) bled into the next function's block and exported it,
  @nord and dot-prefix notwithstanding (#18). Blocks are now strictly
  consecutive #' lines, roxygen2-style. Blank lines and plain # comments
  between a block and its object are still allowed; a block followed by
  another block or EOF warns instead of being silently dropped.

- write_namespace() silently discarded hand-added NAMESPACE directives
  (e.g. a manual useDynLib line with no backing @useDynLib tag) on every
  overwrite (#17). It now warns with the dropped lines and points at the
  matching tag. export() and S3method() churn is exempt.

Also demote cran.R's file header from #' to # (it now attaches to
WEBSERVICE_PACKAGES under the new rules) and document the pkg_generics
parameter of detect_s3_method() and generate_rd(), which warned on
every document() run.
@TroyHernandez TroyHernandez merged commit 7f6dec3 into main Jun 12, 2026
4 checks passed
@TroyHernandez TroyHernandez deleted the fix/block-merging-and-namespace-drops branch June 12, 2026 13:42
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.

Functions with @noRd (and even dot-prefixed names) are still exported document() silently drops manual useDynLib lines (@useDynLib unsupported)

1 participant