Skip to content

Commit 56126ef

Browse files
authored
Merge branch 'main' into obj-name-str
2 parents 90d8f31 + 239de20 commit 56126ef

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
## Bug fixes
44

55
* `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.
6+
* `condition_message_linter()` ignores usages of extracted calls like `env$stop(paste(a, b))` (#1455, @MichaelChirico).
67

78
## New and improved features
89

910
* `library_call_linter()` can detect if all library calls are not at the top of your script (#2027, @nicholas-masel).
1011

11-
1212
## Changes to defaults
1313

1414
* `assignment_linter()` lints the {magrittr} assignment pipe `%<>%` (#2008, @MichaelChirico). This can be deactivated by setting the new argument `allow_pipe_assign` to `TRUE`.
@@ -38,7 +38,7 @@
3838

3939
* `get_source_expressions()` can handle Sweave/Rmarkdown documents with reference chunks like `<<ref_file>>` (#779, @MichaelChirico).
4040
Note that these are simply skipped, rather than attempting to retrieve the reference and also lint it.
41-
41+
4242
* `assignment_linter()` no longer lints assignments in braces that include comments when `allow_trailing = FALSE` (#1701, @ashbaldry)
4343

4444
* `object_usage_linter()`

R/condition_message_linter.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
condition_message_linter <- function() {
4444
translators <- c("packageStartupMessage", "message", "warning", "stop")
4545
xpath <- glue::glue("
46-
//SYMBOL_FUNCTION_CALL[ {xp_text_in_table(translators)} ]
46+
//SYMBOL_FUNCTION_CALL[
47+
({xp_text_in_table(translators)})
48+
and not(preceding-sibling::OP-DOLLAR or preceding-sibling::OP-AT)
49+
]
4750
/parent::expr
4851
/following-sibling::expr[
4952
expr[1][SYMBOL_FUNCTION_CALL[text() = 'paste' or text() = 'paste0']]

tests/testthat/test-condition_message_linter.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ test_that("condition_message_linter skips allowed usages", {
44
expect_lint("stop('a string', 'another')", NULL, linter)
55
expect_lint("warning('a string', 'another')", NULL, linter)
66
expect_lint("message('a string', 'another')", NULL, linter)
7+
# extracted calls likely don't obey base::stop() semantics
8+
expect_lint("ctx$stop(paste('a', 'b'))", NULL, linter)
9+
expect_lint("ctx@stop(paste('a', 'b'))", NULL, linter)
710

8-
# sprintf is OK (really should be gettextf but offering translations
9-
# at google internally is not likely to happen any time soon)
11+
# sprintf is OK -- gettextf() enforcement is left to other linters
1012
expect_lint("stop(sprintf('A %s!', 'string'))", NULL, linter)
1113

1214
# get multiple sep= in one expression

0 commit comments

Comments
 (0)