-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore old behavior of @importFrom in some edge cases #1574
Changes from all commits
81e6f08
763ce14
50038bc
6fb2da8
0c9cada
3fdbe01
7ccc449
2f82c7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -394,32 +394,63 @@ test_that("can extract non-imports from namespace preserving source", { | |||||
expect_equal(namespace_exports(path), lines[c(1:3, 5)]) | ||||||
}) | ||||||
|
||||||
test_that("Invalid imports throw a helpful error", { | ||||||
test_that("invalid imports generate correct declarations", { | ||||||
MichaelChirico marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
# No matched functions --> no output | ||||||
block <- " | ||||||
#' @importFrom utils InvalidUtilsFunction | ||||||
NULL | ||||||
" | ||||||
expect_message(out <- roc_proc_text(namespace_roclet(), block)) | ||||||
expect_equal(out, character()) | ||||||
|
||||||
# Matched functions --> only drop unmatched functions | ||||||
block <- " | ||||||
#' @importFrom utils head InvalidUtilsFunction | ||||||
NULL | ||||||
" | ||||||
expect_snapshot(out <- roc_proc_text(namespace_roclet(), block)) | ||||||
expect_message(out <- roc_proc_text(namespace_roclet(), block)) | ||||||
expect_equal(out, "importFrom(utils,head)") | ||||||
}) | ||||||
|
||||||
test_that("invalid imports generate helpful message", { | ||||||
block <- " | ||||||
#' @importFrom utils head InvalidUtilsFunction1 | ||||||
NULL | ||||||
" | ||||||
expect_snapshot(out <- roc_proc_text(namespace_roclet(), block)) | ||||||
|
||||||
# pluralization | ||||||
block <- " | ||||||
#' @importFrom utils head InvalidUtilsFunction1 InvalidUtilsFunction2 | ||||||
NULL | ||||||
" | ||||||
expect_snapshot(out <- roc_proc_text(namespace_roclet(), block)) | ||||||
expect_equal(out, "importFrom(utils,head)") | ||||||
}) | ||||||
|
||||||
# If the package is not available at roxygenize() run time, nothing we can do | ||||||
test_that("nothing we can do if package isn't installed", { | ||||||
block <- " | ||||||
#' @importFrom AnUnknownUnavailablePackage Unchecked | ||||||
NULL | ||||||
" | ||||||
expect_snapshot(out <- roc_proc_text(namespace_roclet(), block)) | ||||||
expect_no_message(out <- roc_proc_text(namespace_roclet(), block)) | ||||||
expect_equal(out, "importFrom(AnUnknownUnavailablePackage,Unchecked)") | ||||||
|
||||||
}) | ||||||
|
||||||
test_that("non-syntactic imports can use multiple quoting forms", { | ||||||
lines <- c( | ||||||
"#' @importFrom stringr %>%", | ||||||
"#' @importFrom stringr `%>%`", | ||||||
"#' @importFrom stringr '%>%'", | ||||||
"#' @importFrom stringr \"%>%\"", | ||||||
"NULL" | ||||||
) | ||||||
|
||||||
import <- expect_no_warning(roc_proc_text(namespace_roclet(), lines)) | ||||||
expect_equal(import, c( | ||||||
"importFrom(stringr,\"%>%\")", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my edification, any reason to prefer this to
Suggested change
I like this for keeping the 3 lines of code aligned vertically / no need to visually parse escapes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have particularly strong feelings here but I like that currently all the strings use |
||||||
"importFrom(stringr,'%>%')", | ||||||
"importFrom(stringr,`%>%`)" | ||||||
)) | ||||||
}) | ||||||
|
||||||
# warn_missing_s3_exports ------------------------------------------------- | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thought: how do the different types of quoting affect the
NAMESPACE
? Are they normalised elsewhere, or is it ok to use any of the forms without quoting?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean from roxygen2 perspective or base R?
Answering for the latter: NAMESPACE needs to parse as R, so
importFrom(magrittr, %>%)
won't work.So for roxygen2, my understanding is
@importFrom magrittr %>%
will add quotes for convenience (that's the helperauto_quotes
), but quoted forms are dropped in as-is.