diff --git a/R/lint.R b/R/lint.R index 8977ba889..03f599572 100644 --- a/R/lint.R +++ b/R/lint.R @@ -403,17 +403,20 @@ Lint <- function(filename, line_number = 1L, column_number = 1L, # nolint: objec } if (length(line) != 1L || !is.character(line)) { - stop("`line` must be a string.", call. = FALSE) + cli_abort("{.arg line} must be a string.", call. = FALSE) } max_col <- max(nchar(line) + 1L, 1L, na.rm = TRUE) if (!is_number(column_number) || column_number < 0L || column_number > max_col) { - stop(sprintf( - "`column_number` must be an integer between 0 and nchar(line) + 1 (%d). It was %s.", - max_col, column_number - ), call. = FALSE) + cli_abort(c( + i = "{.arg column_number} must be an integer between {.val {0}} and {.code nchar(line) + 1} ({.val {max_col}})", + x = "Instead, it was {.val {column_number}}." + )) } if (!is_number(line_number) || line_number < 1L) { - stop(sprintf("`line_number` must be a positive integer. It was %s.", line_number), call. = FALSE) + cli_abort(c( + i = "{.arg line_number} must be a positive integer.", + x = "Instead, it was {.val {line_number}}." + )) } check_ranges(ranges, max_col) @@ -448,7 +451,10 @@ check_ranges <- function(ranges, max_col) { return() } if (!is.list(ranges)) { - stop("`ranges` must be NULL or a list.", call. = FALSE) + cli_abort(c( + i = "{.arg ranges} must be {.code NULL} or a {.cls list}.", + x = "Instead, it was {.cls {class(ranges)}}." + )) } for (range in ranges) { diff --git a/R/with.R b/R/with.R index aec99dd80..6bc641337 100644 --- a/R/with.R +++ b/R/with.R @@ -209,9 +209,9 @@ call_linter_factory <- function(linter_factory, linter_name, package) { linter <- tryCatch( linter_factory(), error = function(e) { - fun_name <- paste0(package, "::", linter_name) # nolint: object_name_linter + pkg_fn <- paste0(package, "::", linter_name) # nolint: object_name_linter cli_abort(c( - i = "Could not create linter with {.fun fun_name}.", + i = "Could not create linter with {.fun pkg_fn}.", x = conditionMessage(e) )) } diff --git a/tests/testthat/test-Lint-builder.R b/tests/testthat/test-Lint-builder.R index 3d081a1af..4ec7820d7 100644 --- a/tests/testthat/test-Lint-builder.R +++ b/tests/testthat/test-Lint-builder.R @@ -2,15 +2,18 @@ test_that("Lint() errors on invalid input", { dummy_line <- "abc" expect_error( Lint("dummy.R", line = dummy_line, column_number = NA_integer_), - rex::rex("`column_number` must be an integer between 0 and nchar(line) + 1 (4). It was NA.") + "`column_number` must be an integer between 0 and `nchar(line) + 1` (4)", + fixed = TRUE ) expect_error( Lint("dummy.R", line = dummy_line, line_number = 0L), - rex::rex("`line_number` must be a positive integer. It was 0.") + "`line_number` must be a positive integer", + fixed = TRUE ) expect_error( Lint("dummy.R", ranges = c(1L, 3L)), - rex::rex("`ranges` must be NULL or a list.") + "`ranges` must be `NULL` or a ", + fixed = TRUE ) expect_error( Lint("dummy.R", ranges = list(1L)),