diff --git a/NEWS.md b/NEWS.md index 4082dc451f..872fd366b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,8 +6,7 @@ ## Bug fixes -* `inner_combine_linter()` no longer throws on length-1 calls to `c()` like `c(exp(2))` or `c(log(3))` (#2017, @MichaelChirico). Such usage is discouraged by `unnecessary_concatenation_linter()`, but `inner_combine_linter()` _per se_ does not apply. -* `condition_message_linter()` ignores usages of extracted calls like `env$stop(paste(a, b))` (#1455, @MichaelChirico). +* `sprintf_linter()` doesn't error in cases where whitespace in `...` arguments is significant, e.g. `sprintf("%s", if (A) "" else y)`, which won't parse if whitespace is removed (#2131, @MichaelChirico). ## New and improved features @@ -45,6 +44,8 @@ * `unreachable_code_linter()` + finds unreachable code even in the presence of a comment or semicolon after `return()` or `stop()` (#2127, @MEO265). + checks for code inside `if (FALSE)` and other conditional loops with deterministically false conditions (#1428, @ME0265). +* `inner_combine_linter()` no longer throws on length-1 calls to `c()` like `c(exp(2))` or `c(log(3))` (#2017, @MichaelChirico). Such usage is discouraged by `unnecessary_concatenation_linter()`, but `inner_combine_linter()` _per se_ does not apply. +* `condition_message_linter()` ignores usages of extracted calls like `env$stop(paste(a, b))` (#1455, @MichaelChirico). ### New linters diff --git a/R/utils.R b/R/utils.R index 4741b16624..505eeed59a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -257,7 +257,7 @@ get_r_string <- function(s, xpath = NULL) { #' @noRd xml2lang <- function(x) { x_strip_comments <- xml_find_all(x, ".//*[not(self::COMMENT or self::expr)]") - str2lang(paste(xml_text(x_strip_comments), collapse = "")) + str2lang(paste(xml_text(x_strip_comments), collapse = " ")) } is_linter <- function(x) inherits(x, "linter") diff --git a/tests/testthat/test-sprintf_linter.R b/tests/testthat/test-sprintf_linter.R index d1921018dd..3e9b9c4cd1 100644 --- a/tests/testthat/test-sprintf_linter.R +++ b/tests/testthat/test-sprintf_linter.R @@ -90,6 +90,9 @@ test_that("edge cases are detected correctly", { list(message = rex::rex("reference to non-existent argument 3")), linter ) + + # #2131: xml2lang stripped necessary whitespace + expect_lint("sprintf('%s', if (A) '' else y)", NULL, linter) }) local({