Skip to content

Commit 72e57b8

Browse files
Error earlier for missing lint_message (#2541)
* Error earlier for missing lint_message * include PR#
1 parent 713fb0b commit 72e57b8

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* `todo_comment_linter()` has a new argument `except_regex` for setting _valid_ TODO comments, e.g. for forcing TODO comments to be linked to GitHub issues like `TODO(#154)` (#2047, @MichaelChirico).
5050
* `vector_logic_linter()` is extended to recognize incorrect usage of scalar operators `&&` and `||` inside subsetting expressions like `dplyr::filter(x, A && B)` (#2166, @MichaelChirico).
5151
* `any_is_na_linter()` is extended to catch the unusual usage `NA %in% x` (#2113, @MichaelChirico).
52+
* `make_linter_from_xpath()` errors up front when `lint_message` is missing (instead of delaying this error until the linter is used, #2541, @MichaelChirico).
5253

5354
### New linters
5455

R/make_linter_from_xpath.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ make_linter_from_xpath <- function(xpath,
1919
level <- match.arg(level)
2020

2121
stopifnot(
22-
"xpath should be a character string" = is.character(xpath) && length(xpath) == 1L && !is.na(xpath)
22+
"xpath should be a character string" = is.character(xpath) && length(xpath) == 1L && !is.na(xpath),
23+
"lint_message is required" = !missing(lint_message)
2324
)
2425

2526
xml_key <- if (level == "expression") "xml_parsed_content" else "full_xml_parsed_content"
@@ -55,7 +56,8 @@ make_linter_from_function_xpath <- function(function_names,
5556

5657
stopifnot(
5758
"function_names should be a character vector" = is.character(function_names) && length(function_names) > 0L,
58-
"xpath should be a character string" = is.character(xpath) && length(xpath) == 1L && !is.na(xpath)
59+
"xpath should be a character string" = is.character(xpath) && length(xpath) == 1L && !is.na(xpath),
60+
"lint_message is required" = !missing(lint_message)
5961
)
6062

6163
function() {

tests/testthat/test-make_linter_from_xpath.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ test_that("input validation works", {
2626
expect_error(make_linter_from_xpath(letters), err_msg, fixed = TRUE)
2727
expect_error(make_linter_from_xpath(NA_character_), err_msg, fixed = TRUE)
2828
expect_error(make_linter_from_xpath(character()), err_msg, fixed = TRUE)
29+
30+
err_msg <- if (getRversion() < "4.0.0") "!missing(lint_message)" else "lint_message is required"
31+
expect_error(make_linter_from_xpath(""), err_msg, fixed = TRUE)
2932
})

0 commit comments

Comments
 (0)