Skip to content

Commit 38a6f8c

Browse files
ateucherjennybc
andauthored
Implement type checkers from rlang standalone-types-check.R (#1820)
* Add rlang standalone files * update rlang version * Use rlang argument checkers * rlang arg checkers in github-actions.R * Simplify logic when url & name are NULL * Add checks * Bump standalone-types-check.R * type-checking in utils-github.R and write.R * Use check_character on df columns * More checkers * implement maybe_name() * remove dev rlang from remotes * change regex-based error expectation to snapshot test Co-authored-by: Jennifer (Jenny) Bryan <[email protected]> * Change expect_error() to expect_snapshot(error = TRUE) * Add back check for length of lines --------- Co-authored-by: Jennifer (Jenny) Bryan <[email protected]>
1 parent c3c0f5b commit 38a6f8c

25 files changed

+991
-67
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Imports:
3333
lifecycle (>= 1.0.0),
3434
purrr,
3535
rappdirs,
36-
rlang (>= 1.0.0),
36+
rlang (>= 1.1.0),
3737
rprojroot (>= 1.2),
3838
rstudioapi,
3939
stats,

R/browse.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ NULL
5757
#' @export
5858
#' @rdname browse-this
5959
browse_package <- function(package = NULL) {
60-
stopifnot(is.null(package) || is_string(package))
60+
maybe_name(package)
61+
6162
if (is.null(package)) {
6263
check_is_project()
6364
}
@@ -156,7 +157,7 @@ browse_cran <- function(package = NULL) {
156157
# 2. BugReports/URL fields of DESCRIPTION (active project or arbitrary
157158
# installed package)
158159
github_url <- function(package = NULL) {
159-
stopifnot(is.null(package) || is_string(package))
160+
maybe_name(package)
160161

161162
if (is.null(package)) {
162163
check_is_project()

R/course.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ tidy_unzip <- function(zipfile, cleanup = FALSE) {
410410
#' create_download_url("https://drive.google.com/open?id=123456789xxyyyzzz/view")
411411
#' @export
412412
create_download_url <- function(url) {
413-
stopifnot(is_string(url))
413+
check_name(url)
414414
stopifnot(grepl("^http[s]?://", url))
415415

416416
switch(
@@ -469,7 +469,7 @@ hopeless_url <- function(url) {
469469
}
470470

471471
normalize_url <- function(url) {
472-
stopifnot(is.character(url))
472+
check_name(url)
473473
has_scheme <- grepl("^http[s]?://", url)
474474

475475
if (has_scheme) {
@@ -603,7 +603,7 @@ make_filename <- function(cd,
603603
## https://tools.ietf.org/html/rfc6266
604604
cd <- cd[["filename"]]
605605
if (is.null(cd) || is.na(cd)) {
606-
stopifnot(is_string(fallback))
606+
check_name(fallback)
607607
return(path_sanitize(fallback))
608608
}
609609

R/data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ check_files_absent <- function(paths, overwrite) {
128128
#' use_data_raw("daisy")
129129
#' }
130130
use_data_raw <- function(name = "DATASET", open = rlang::is_interactive()) {
131-
stopifnot(is_string(name))
131+
check_name(name)
132132
r_path <- path("data-raw", asciify(name), ext = "R")
133133
use_directory("data-raw", ignore = TRUE)
134134

R/git-default-branch.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ git_default_branch_rediscover <- function(current_local_default = NULL) {
318318
#' }
319319
git_default_branch_rename <- function(from = NULL, to = "main") {
320320
repo <- git_repo()
321-
maybe_string(from)
322-
check_string(to)
321+
maybe_name(from)
322+
check_name(to)
323323

324324
if (!is.null(from) &&
325325
!gert::git_branch_exists(from, local = TRUE, repo = repo)) {
@@ -395,7 +395,7 @@ git_default_branch_rename <- function(from = NULL, to = "main") {
395395
}
396396

397397
rediscover_default_branch <- function(old_name = NULL, report_on_source = TRUE) {
398-
maybe_string(old_name)
398+
maybe_name(old_name)
399399

400400
# GitHub's official TODOs re: manually updating local environments
401401
# after a source repo renames the default branch:

R/git.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ check_protocol <- function(protocol) {
243243
#' use_git_remote(name = "upstream", url = upstream_url)
244244
#' }
245245
use_git_remote <- function(name = "origin", url, overwrite = FALSE) {
246-
stopifnot(is_string(name))
247-
stopifnot(is.null(url) || is_string(url))
248-
stopifnot(is_true(overwrite) || is_false(overwrite))
246+
check_name(name)
247+
maybe_name(url)
248+
check_bool(overwrite)
249249

250250
remotes <- git_remotes()
251251
repo <- git_repo()

R/github-actions.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ use_github_action <- function(name = NULL,
7070
open = FALSE,
7171
badge = NULL) {
7272

73-
if (is.null(url) && is.null(name)) {
74-
name <- choose_gha_workflow()
75-
}
73+
maybe_name(name)
74+
maybe_name(ref)
75+
maybe_name(url)
76+
maybe_name(save_as)
77+
maybe_name(readme)
78+
check_bool(ignore)
79+
check_bool(open)
80+
check_bool(badge, allow_null = TRUE)
7681

7782
if (is.null(url)) {
78-
check_string(name)
79-
maybe_string(ref)
83+
84+
name <- name %||% choose_gha_workflow()
8085

8186
if (path_ext(name) == "") {
8287
name <- path_ext_set(name, "yaml")
@@ -89,10 +94,8 @@ use_github_action <- function(name = NULL,
8994
readme <- glue(
9095
"https://github.com/r-lib/actions/blob/{ref}/examples/README.md"
9196
)
92-
} else {
93-
check_string(url)
94-
maybe_string(readme)
9597
}
98+
9699
withr::defer(rstudio_git_tickle())
97100

98101
use_dot_github(ignore = ignore)
@@ -104,7 +107,7 @@ use_github_action <- function(name = NULL,
104107
save_as <- path_file(url)
105108
}
106109
}
107-
check_string(save_as)
110+
108111
save_as <- path(".github", "workflows", save_as)
109112
create_directory(path_dir(proj_path(save_as)))
110113

R/github-pages.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@
4949
#' use_github_pages(branch = git_default_branch(), path = "/docs")
5050
#' }
5151
use_github_pages <- function(branch = "gh-pages", path = "/", cname = NA) {
52-
stopifnot(is_string(branch), is_string(path))
53-
stopifnot(is.na(cname) || is.null(cname) || is_string(cname))
52+
check_name(branch)
53+
check_name(path)
54+
check_string(cname, allow_empty = FALSE, allow_na = TRUE, allow_null = TRUE)
5455
tr <- target_repo(github_get = TRUE, ok_configs = c("ours", "fork"))
5556
check_can_push(tr = tr, "to turn on GitHub Pages")
5657

R/helpers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use_dependency <- function(package, type, min_version = NULL) {
2-
stopifnot(is_string(package))
3-
stopifnot(is_string(type))
2+
check_name(package)
3+
check_name(type)
44

55
if (package != "R") {
66
check_installed(package)

0 commit comments

Comments
 (0)