From f0d9407306d9c6d2f049ac6f698d2806d44a989c Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Thu, 18 Jul 2024 22:40:25 +0200 Subject: [PATCH 1/3] Don't include GHA log output in pkgdown website (#2633) * Don't include GHA log output in pkgdown website * add a test * extra blank line * make future-proof --------- Co-authored-by: Michael Chirico --- R/actions.R | 4 ++++ R/methods.R | 2 +- tests/testthat/test-ci.R | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/R/actions.R b/R/actions.R index 9a20a1986..606442b8f 100644 --- a/R/actions.R +++ b/R/actions.R @@ -2,6 +2,10 @@ in_github_actions <- function() { identical(Sys.getenv("GITHUB_ACTIONS"), "true") } +in_pkgdown <- function() { + identical(Sys.getenv("IN_PKGDOWN"), "true") +} + # Output logging commands for any lints found github_actions_log_lints <- function(lints, project_dir = "") { for (x in lints) { diff --git a/R/methods.R b/R/methods.R index 46e8ed804..29a974d48 100644 --- a/R/methods.R +++ b/R/methods.R @@ -92,7 +92,7 @@ print.lints <- function(x, ...) { inline_data <- x[[1L]][["filename"]] == "" if (!inline_data && use_rstudio_source_markers) { rstudio_source_markers(x) - } else if (in_github_actions()) { + } else if (in_github_actions() && !in_pkgdown()) { github_actions_log_lints(x, project_dir = github_annotation_project_dir) } else { lapply(x, print, ...) diff --git a/tests/testthat/test-ci.R b/tests/testthat/test-ci.R index 3f4f98762..40401e934 100644 --- a/tests/testthat/test-ci.R +++ b/tests/testthat/test-ci.R @@ -1,5 +1,5 @@ test_that("GitHub Actions functionality works", { - withr::local_envvar(list(GITHUB_ACTIONS = "true")) + withr::local_envvar(list(GITHUB_ACTIONS = "true", IN_PKGDOWN = "false")) withr::local_options(lintr.rstudio_source_markers = FALSE) tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)") @@ -26,7 +26,7 @@ test_that("GitHub Actions functionality works in a subdirectory", { patrick::with_parameters_test_that( "GitHub Actions - error on lint works", { - withr::local_envvar(list(GITHUB_ACTIONS = "true", LINTR_ERROR_ON_LINT = env_var_value)) + withr::local_envvar(list(GITHUB_ACTIONS = "true", IN_PKGDOWN = "", LINTR_ERROR_ON_LINT = env_var_value)) withr::local_options(lintr.rstudio_source_markers = FALSE) tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)") @@ -51,3 +51,12 @@ patrick::with_parameters_test_that( }, env_var_value = list("", "F", NA, NULL) ) + +test_that("GitHub Actions log is skipped in pkgdown websites", { + withr::local_envvar(list(GITHUB_ACTIONS = "true", IN_PKGDOWN = "true")) + withr::local_options(lintr.rstudio_source_markers = FALSE) + tmp <- withr::local_tempfile(lines = "x <- 1:nrow(y)") + + l <- lint(tmp, linters = seq_linter()) + expect_output(print(l), "warning: [seq_linter]", fixed = TRUE) +}) From f2da882ce6d8889842b8b46294b367ff734f6513 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 24 Jul 2024 11:00:30 +0200 Subject: [PATCH 2/3] Fix missing DCF code block on website (#2635) --- DESCRIPTION | 2 +- R/settings.R | 2 +- man/read_settings.Rd | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4831fe875..ff326321a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,7 +55,7 @@ Config/Needs/development: pkgload, cli, testthat, patrick Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Collate: 'make_linter_from_xpath.R' 'xp_utils.R' diff --git a/R/settings.R b/R/settings.R index 9bd7da159..475467335 100644 --- a/R/settings.R +++ b/R/settings.R @@ -12,7 +12,7 @@ #' This file is a DCF file, see [base::read.dcf()] for details. #' Here is an example of a `.lintr` file: #' -#' ```dcf +#' ``` #' linters: linters_with_defaults( #' any_duplicated_linter(), #' any_is_na_linter(), diff --git a/man/read_settings.Rd b/man/read_settings.Rd index cbb1dc9ec..84e53666e 100644 --- a/man/read_settings.Rd +++ b/man/read_settings.Rd @@ -27,7 +27,7 @@ or the environment variable \code{R_LINTR_LINTER_FILE} This file is a DCF file, see \code{\link[base:dcf]{base::read.dcf()}} for details. Here is an example of a \code{.lintr} file: -\if{html}{\out{
}}\preformatted{linters: linters_with_defaults( +\if{html}{\out{
}}\preformatted{linters: linters_with_defaults( any_duplicated_linter(), any_is_na_linter(), backport_linter("oldrel-4", except = c("R_user_dir", "str2lang")), From 3358539520a089e8267bdbbe0764537b96c24414 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 5 Aug 2024 22:38:34 +0200 Subject: [PATCH 3/3] Print a message when no lints found (#2643) * Print a message when no lints found closes #2640 * use info markup * Update NEWS.md * delint * more inlining * use single if-else * Create a separate NEWS entry * don't install quarto to avoid NOTE --- .github/workflows/R-CMD-check-hard.yaml | 1 + .github/workflows/R-CMD-check.yaml | 1 + NEWS.md | 1 + R/methods.R | 10 +++++++--- tests/testthat/test-methods.R | 7 +++++++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check-hard.yaml b/.github/workflows/R-CMD-check-hard.yaml index 54db1e064..977807d3c 100644 --- a/.github/workflows/R-CMD-check-hard.yaml +++ b/.github/workflows/R-CMD-check-hard.yaml @@ -48,6 +48,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: + install-quarto: false pak-version: devel dependencies: '"hard"' cache: false diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 110d148cb..f0848b43b 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -70,6 +70,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: + install-quarto: false extra-packages: | any::rcmdcheck needs: check diff --git a/NEWS.md b/NEWS.md index 140ee54ea..68ef13f8d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -58,6 +58,7 @@ * `make_linter_from_xpath()` errors up front when `lint_message` is missing (instead of delaying this error until the linter is used, #2541, @MichaelChirico). * `paste_linter()` is extended to recommend using `paste()` instead of `paste0()` for simply aggregating a character vector with `collapse=`, i.e., when `sep=` is irrelevant (#1108, @MichaelChirico). * `expect_no_lint()` was added as new function to cover the typical use case of expecting no lint message, akin to the recent {testthat} functions like `expect_no_warning()` (#2580, @F-Noelle). +* `lint()` and friends emit a message if no lints are found (#2643, @IndrajeetPatil). ### New linters diff --git a/R/methods.R b/R/methods.R index 29a974d48..869c17ef1 100644 --- a/R/methods.R +++ b/R/methods.R @@ -101,10 +101,14 @@ print.lints <- function(x, ...) { if (isTRUE(settings$error_on_lint)) { quit("no", 31L, FALSE) # nocov } - } else if (use_rstudio_source_markers) { - # Empty lints: clear RStudio source markers - rstudio_source_markers(x) + } else { + # Empty lints + cli_inform(c(i = "No lints found.")) + if (use_rstudio_source_markers) { + rstudio_source_markers(x) # clear RStudio source markers + } } + invisible(x) } diff --git a/tests/testthat/test-methods.R b/tests/testthat/test-methods.R index 172b9692d..b337169f1 100644 --- a/tests/testthat/test-methods.R +++ b/tests/testthat/test-methods.R @@ -96,6 +96,13 @@ test_that("print.lint works", { expect_output(print(l), " 1:length(x)", fixed = TRUE) }) +test_that("print.lint works with empty lints", { + withr::local_options(list(lintr.rstudio_source_markers = FALSE)) + l <- lint(text = "1L") + + expect_message(print(l), "No lints found", fixed = TRUE) +}) + test_that("print.lint works for inline data, even in RStudio", { l <- lint("x = 1\n")