Skip to content

Commit

Permalink
Merge branch 'main' into allow-fn-brace
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Aug 6, 2024
2 parents 7620e37 + 3358539 commit 2dc893e
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/R-CMD-check-hard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
install-quarto: false
pak-version: devel
dependencies: '"hard"'
cache: false
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
install-quarto: false
extra-packages: |
any::rcmdcheck
needs: check
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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

Expand Down
4 changes: 4 additions & 0 deletions R/actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ print.lints <- function(x, ...) {
inline_data <- x[[1L]][["filename"]] == "<text>"
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, ...)
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion R/settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion man/read_settings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions tests/testthat/test-ci.R
Original file line number Diff line number Diff line change
@@ -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)")

Expand All @@ -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)")

Expand All @@ -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)
})
7 changes: 7 additions & 0 deletions tests/testthat/test-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 2dc893e

Please sign in to comment.