Skip to content

Commit 72eeefd

Browse files
use trim_some() consistently (#2461)
Co-authored-by: AshesITR <[email protected]>
1 parent 033c0d9 commit 72eeefd

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

tests/testthat/test-commented_code_linter.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ test_that("commented_code_linter skips allowed usages", {
33

44
expect_lint("blah", NULL, linter)
55
expect_lint("#' blah <- 1", NULL, linter)
6-
expect_lint(c("a <- 1", "# comment without code"), NULL, linter)
7-
expect_lint(c("a <- 1", "# comment without code"), NULL, linter)
8-
expect_lint(c("a <- 1", "## whatever"), NULL, linter)
6+
expect_lint("a <- 1\n# comment without code", NULL, linter)
7+
expect_lint("a <- 1\n## whatever", NULL, linter)
98

109
expect_lint("TRUE", NULL, linter)
1110
expect_lint("#' @examples", NULL, linter)

tests/testthat/test-expect_lint.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ test_that("multiple checks", {
4242
expect_success(expect_lint("a=1; b=2", list(c(message = lint_msg), c(message = lint_msg)), linter))
4343
expect_success(expect_lint("a=1; b=2", list(c(line_number = 1L), c(linter = "assignment_linter")), linter))
4444
expect_success(expect_lint("a=1; b=2", list(lint_msg, c(line = "a=1; b=2", type = "warning")), linter))
45-
expect_success(expect_lint(c("a=1", "b=2"), list(c(line_number = 1L), c(line_number = 2L)), linter))
46-
expect_failure(expect_lint(c("a=1", "b=2"), list(c(line_number = 2L), c(line_number = 2L)), linter))
45+
expect_success(expect_lint("a=1\nb=2", list(c(line_number = 1L), c(line_number = 2L)), linter))
46+
expect_failure(expect_lint("a=1\nb=2", list(c(line_number = 2L), c(line_number = 2L)), linter))
4747

4848
expect_success(expect_lint("a=1; b=2", list(list(line_number = 1L), list(line_number = 2L)), linter))
4949
expect_failure(expect_lint("a=1; b=2", list(list(line_number = 2L), list(line_number = 2L)), linter))

tests/testthat/test-library_call_linter.R

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,26 @@ patrick::with_parameters_test_that(
331331
expect_lint(sprintf("%1$s(x); y; %1$s(z)", call), NULL, linter)
332332

333333
# inline or potentially with gaps don't matter
334-
lines <- c(
335-
sprintf("%s(x)", call),
336-
"y",
337-
"",
338-
"stopifnot(z)"
334+
expect_lint(
335+
trim_some(glue::glue("
336+
{call}(x)
337+
y
338+
339+
stopifnot(z)
340+
")),
341+
NULL,
342+
linter
339343
)
340-
expect_lint(lines, NULL, linter)
341344

342345
# only suppressing calls with library()
343-
lines_consecutive <- c(
344-
sprintf("%s(x)", call),
345-
sprintf("%s(y)", call)
346+
expect_lint(
347+
trim_some(glue::glue("
348+
{call}(x)
349+
{call}(y)
350+
")),
351+
NULL,
352+
linter
346353
)
347-
expect_lint(lines_consecutive, NULL, linter)
348354
},
349355
.test_name = c("suppressMessages", "suppressPackageStartupMessages"),
350356
call = c("suppressMessages", "suppressPackageStartupMessages")
@@ -359,25 +365,34 @@ patrick::with_parameters_test_that(
359365
# one test of inline usage
360366
expect_lint(sprintf("%1$s(library(x)); %1$s(library(y))", call), message, linter)
361367

362-
lines_gap <- c(
363-
sprintf("%s(library(x))", call),
364-
"",
365-
sprintf("%s(library(y))", call)
368+
expect_lint(
369+
trim_some(glue::glue("
370+
{call}(library(x))
371+
372+
{call}(library(y))
373+
")),
374+
message,
375+
linter
366376
)
367-
expect_lint(lines_gap, message, linter)
368377

369-
lines_consecutive <- c(
370-
sprintf("%s(require(x))", call),
371-
sprintf("%s(require(y))", call)
378+
expect_lint(
379+
trim_some(glue::glue("
380+
{call}(require(x))
381+
{call}(require(y))
382+
")),
383+
message,
384+
linter
372385
)
373-
expect_lint(lines_consecutive, message, linter)
374386

375-
lines_comment <- c(
376-
sprintf("%s(library(x))", call),
377-
"# a comment on y",
378-
sprintf("%s(library(y))", call)
387+
expect_lint(
388+
trim_some(glue::glue("
389+
{call}(library(x))
390+
# a comment on y
391+
{call}(library(y))
392+
")),
393+
message,
394+
linter
379395
)
380-
expect_lint(lines_comment, message, linter)
381396
},
382397
.test_name = c("suppressMessages", "suppressPackageStartupMessages"),
383398
call = c("suppressMessages", "suppressPackageStartupMessages")

tests/testthat/test-object_name_linter.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test_that("linter accepts vector of styles", {
9696
linter <- object_name_linter(styles = c("camelCase", "dotted.case"))
9797

9898
expect_lint(
99-
c("var.one <- 1", "varTwo <- 2", "var_three <- 3"),
99+
"var.one <- 1\nvarTwo <- 2\nvar_three <- 3",
100100
list(message = lint_msg, line_number = 3L, column_number = 1L),
101101
linter
102102
)

0 commit comments

Comments
 (0)