Skip to content

Commit

Permalink
Merge 2438526 into 8ac582c
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Sep 11, 2023
2 parents 8ac582c + 2438526 commit ce59503
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-sprintf_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit ce59503

Please sign in to comment.