From 1a19f69301d6123a135a17cb49431f8715c2cd73 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 23 Apr 2026 11:27:21 -0500 Subject: [PATCH] Only warn once when parsing namespace tags --- R/namespace.R | 8 +++++++- tests/testthat/_snaps/namespace.md | 10 ++++++++++ tests/testthat/test-namespace.R | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/R/namespace.R b/R/namespace.R index 62afb7f0..eae0f805 100644 --- a/R/namespace.R +++ b/R/namespace.R @@ -93,7 +93,13 @@ namespace_imports <- function(base_path = ".") { paths <- package_files(base_path) parsed <- lapply(paths, parse, keep.source = TRUE) srcrefs <- lapply(parsed, utils::getSrcref) - blocks <- unlist(lapply(srcrefs, namespace_imports_blocks), recursive = FALSE) + # Ensure parse warnings only fire once during the main parse_package() pass + suppressMessages( + blocks <- unlist( + lapply(srcrefs, namespace_imports_blocks), + recursive = FALSE + ) + ) blocks_to_ns(blocks, emptyenv()) } diff --git a/tests/testthat/_snaps/namespace.md b/tests/testthat/_snaps/namespace.md index 2f2ebb6f..a6336eab 100644 --- a/tests/testthat/_snaps/namespace.md +++ b/tests/testthat/_snaps/namespace.md @@ -1,3 +1,13 @@ +# parsing warnings only fire once + + Code + roxygenise(path) + Message + Writing 'NAMESPACE' + i Loading testNamespace + x multiline.R:1: @importFrom must be only 1 line long, not 2. + i The first line is "stats median" + # @exportS3Method generates fully automatically Code diff --git a/tests/testthat/test-namespace.R b/tests/testthat/test-namespace.R index 5b43adb6..f3f4a6b3 100644 --- a/tests/testthat/test-namespace.R +++ b/tests/testthat/test-namespace.R @@ -16,6 +16,20 @@ test_that("end-to-end NAMESPACE generation works", { ) }) +test_that("parsing warnings only fire once", { + path <- local_package_copy(test_path("testNamespace")) + write_lines( + c("#' @importFrom stats median", "#' ave", "NULL"), + file.path(path, "R", "multiline.R") + ) + withr::defer(pkgload::unload("testNamespace")) + + # Warning fires once (during the main parse_package() pass), + # not also during update_namespace_imports()'s early pass. + expect_snapshot(roxygenise(path)) +}) + + # @export ----------------------------------------------------------------- test_that("export quote object name appropriate", {