From 14ac3262fdceba632f9757ac6c1f91d244f22bef Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 10 Dec 2025 22:44:19 +0000 Subject: [PATCH 1/3] move paren_body_linter hit onto ) --- R/paren_body_linter.R | 3 +-- tests/testthat/test-paren_body_linter.R | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/R/paren_body_linter.R b/R/paren_body_linter.R index a758507b2..75d0b9b16 100644 --- a/R/paren_body_linter.R +++ b/R/paren_body_linter.R @@ -38,13 +38,12 @@ paren_body_linter <- make_linter_from_xpath( or preceding-sibling::WHILE ) ] - /following-sibling::expr[1] | //forcond[ @line1 = following-sibling::expr/@line2 and OP-RIGHT-PAREN/@col1 = following-sibling::expr/@col1 - 1 ] - /following-sibling::expr + /OP-RIGHT-PAREN ", lint_message = "Put a space between a right parenthesis and a body expression.", type = "style" diff --git a/tests/testthat/test-paren_body_linter.R b/tests/testthat/test-paren_body_linter.R index e461ea1a3..476a7b5cc 100644 --- a/tests/testthat/test-paren_body_linter.R +++ b/tests/testthat/test-paren_body_linter.R @@ -1,4 +1,4 @@ -testthat::test_that("paren_body_linter returns correct lints", { +test_that("paren_body_linter returns correct lints", { linter <- paren_body_linter() lint_msg <- rex::rex("Put a space between a right parenthesis and a body expression.") @@ -26,14 +26,20 @@ testthat::test_that("paren_body_linter returns correct lints", { "function()test", list( line_number = 1L, - column_number = 11L, + column_number = 10L, type = "style", line = "function()test", - ranges = list(c(11L, 14L)) + ranges = list(c(10L, 10L)) ), linter ) + expect_lint( + "for (ii in 1:10)ii", + list(column_number = 16L, ranges = list(c(16L, 16L))), + linter + ) + # paren_body_linter does not lint when the function body is defined on a new line expect_lint("function()\n test", NULL, linter) From 8c053a6f40560f72a18f9fef4eb35ef9974cfc27 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 10 Dec 2025 22:46:54 +0000 Subject: [PATCH 2/3] remove testthat:: in more places --- tests/testthat/helper.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 626293795..a99bf55f7 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -58,15 +58,15 @@ with_config <- function(contents, code, config_dir = ".", filename = ".lintr") { } skip_if_not_utf8_locale <- function() { - testthat::skip_if_not(l10n_info()[["UTF-8"]], "Not a UTF-8 locale") + skip_if_not(l10n_info()[["UTF-8"]], "Not a UTF-8 locale") } safe_load_help_db <- function() { help_db <- tryCatch(tools::Rd_db("lintr"), error = \(e) NULL) # e.g. in dev under pkgload::load_all() if (length(help_db) == 0L) { - help_db <- tryCatch(tools::Rd_db(dir = testthat::test_path("..", "..")), error = \(e) NULL) - testthat::skip_if_not(length(help_db) > 0L, message = "Package help corrupted or not installed") + help_db <- tryCatch(tools::Rd_db(dir = test_path("..", "..")), error = \(e) NULL) + skip_if_not(length(help_db) > 0L, message = "Package help corrupted or not installed") } help_db } From fe18720baa9f59ec3dfb1ac4cf6c45cfb7fc49a0 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Wed, 10 Dec 2025 22:54:33 +0000 Subject: [PATCH 3/3] revert chagnes b/c of new lint --- tests/testthat/helper.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index a99bf55f7..626293795 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -58,15 +58,15 @@ with_config <- function(contents, code, config_dir = ".", filename = ".lintr") { } skip_if_not_utf8_locale <- function() { - skip_if_not(l10n_info()[["UTF-8"]], "Not a UTF-8 locale") + testthat::skip_if_not(l10n_info()[["UTF-8"]], "Not a UTF-8 locale") } safe_load_help_db <- function() { help_db <- tryCatch(tools::Rd_db("lintr"), error = \(e) NULL) # e.g. in dev under pkgload::load_all() if (length(help_db) == 0L) { - help_db <- tryCatch(tools::Rd_db(dir = test_path("..", "..")), error = \(e) NULL) - skip_if_not(length(help_db) > 0L, message = "Package help corrupted or not installed") + help_db <- tryCatch(tools::Rd_db(dir = testthat::test_path("..", "..")), error = \(e) NULL) + testthat::skip_if_not(length(help_db) > 0L, message = "Package help corrupted or not installed") } help_db }