Skip to content

Commit

Permalink
Print a message when no lints found (#2643)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
IndrajeetPatil authored Aug 5, 2024
1 parent f2da882 commit 3358539
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 3358539

Please sign in to comment.