Skip to content

Commit 36f04dc

Browse files
Merge branch 'main' into allow-filter
2 parents 7f79d13 + 8cdf26c commit 36f04dc

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
### New linters
5959

60-
* `library_call_linter()` can detect if all library/require calls are not at the top of your script (#2027 and #2043, @nicholas-masel and @MichaelChirico).
60+
* `library_call_linter()` can detect if all library/require calls are not at the top of your script (#2027, #2043, and #2163, @nicholas-masel and @MichaelChirico).
6161
* `keyword_quote_linter()` for finding unnecessary or discouraged quoting of symbols in assignment, function arguments, or extraction (part of #884, @MichaelChirico). Quoting is unnecessary when the target is a valid R name, e.g. `c("a" = 1)` can be `c(a = 1)`. The same goes to assignment (`"a" <- 1`) and extraction (`x$"a"`). Where quoting is necessary, the linter encourages doing so with backticks (e.g. `` x$`a b` `` instead of `x$"a b"`).
6262
* `length_levels_linter()` for using the specific function `nlevels()` instead of checking `length(levels(x))` (part of #884, @MichaelChirico).
6363
* `scalar_in_linter()` for discouraging `%in%` when the right-hand side is a scalar, e.g. `x %in% 1` (part of #884, @MichaelChirico).

R/library_call_linter.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ library_call_linter <- function() {
4848
xpath <- glue("
4949
//SYMBOL_FUNCTION_CALL[{ attach_call }][last()]
5050
/preceding::expr
51-
/SYMBOL_FUNCTION_CALL[not({ attach_call })][last()]
51+
/SYMBOL_FUNCTION_CALL[not({ attach_call } or starts-with(text(), 'suppress'))][last()]
5252
/following::expr[SYMBOL_FUNCTION_CALL[{ attach_call }]]
5353
/parent::expr
5454
")

tests/testthat/test-library_call_linter.R

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ test_that("library_call_linter skips allowed usages", {
3232
NULL,
3333
linter
3434
)
35+
36+
expect_lint(
37+
trim_some("
38+
suppressPackageStartupMessages({
39+
library(dplyr)
40+
library(knitr)
41+
})
42+
"),
43+
NULL,
44+
linter
45+
)
3546
})
3647

3748
test_that("library_call_linter warns on disallowed usages", {
@@ -108,6 +119,17 @@ test_that("library_call_linter warns on disallowed usages", {
108119
lint_message,
109120
linter
110121
)
122+
123+
expect_lint(
124+
trim_some("
125+
library(dplyr)
126+
print('test')
127+
suppressMessages(library(tidyr))
128+
print('test')
129+
"),
130+
lint_message,
131+
linter
132+
)
111133
})
112134

113135
test_that("require() treated the same as library()", {

0 commit comments

Comments
 (0)