diff --git a/DESCRIPTION b/DESCRIPTION index cab29783d..3dd6bf9e4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: precommit Title: Pre-Commit Hooks -Version: 0.4.3.9018 +Version: 0.4.3.9019 Author: Lorenz Walthert Maintainer: Lorenz Walthert Description: Useful git hooks for R building on top of the multi-language diff --git a/R/setup.R b/R/setup.R index 5b57833ed..05183cfb4 100644 --- a/R/setup.R +++ b/R/setup.R @@ -133,6 +133,15 @@ use_ci <- function(ci = getOption("precommit.ci", "native"), "proceed." )) } + + if (length(grep("^ *- *id *: *lintr", config)) > 0) { + cli::cli_ul(paste0( + "It seems like you are using the lintr hook. This requires further ", + "edits in your {.code .pre-commit-config.yaml}, please run ", + "{.code precommit::snippet_generate('additional-deps-lintr')} to ", + "proceed." + )) + } } #' Auto-update your hooks @@ -263,8 +272,17 @@ snippet_generate <- function(snippet = "additional-deps-roxygenize", "\n" )) deps <- desc::desc_get_deps() - hard_dependencies <- deps[(deps$type %in% c("Depends", "Imports")), "package"] %>% + + # Add Suggests for lintr, so it works on vignettes, readme, etc. + dep_types <- if (snippet == "additional-deps-lintr") { + c("Depends", "Imports", "Suggests") + } else { + c("Depends", "Imports") + } + + hard_dependencies <- deps[(deps$type %in% dep_types), "package"] %>% setdiff("R") + if (length(hard_dependencies) < 1) { cli::cli_alert_success(paste0( "According to {.code DESCRIPTION}`, there are no hard dependencies of ", @@ -277,10 +295,7 @@ snippet_generate <- function(snippet = "additional-deps-roxygenize", snippet_generator() %>% cat(sep = "") cat("\n") - cli::cli_ul(paste0( - "Replace the `id: roxygenize` key in `.pre-commit-config.yaml` with the ", - "above code." - )) + cli::cli_alert_info(paste0( "Note that CI services like {.url pre-commit.ci} have build-time ", "restrictions and installing the above dependencies may exceed those, ", @@ -334,6 +349,7 @@ snippet_generate_impl_additional_deps_lintr <- function(packages, with_version = ) %>% sort() paste0(" - id: lintr - # lintr requires loading pkg -> add dependencies from DESCRIPTION + # lintr requires loading pkg -> add dependencies (incl. Suggests) from DESCRIPTION + args: [--load_package] additional_dependencies:\n", out) } diff --git a/inst/pre-commit-config-pkg.yaml b/inst/pre-commit-config-pkg.yaml index c006f7e26..3210fd292 100644 --- a/inst/pre-commit-config-pkg.yaml +++ b/inst/pre-commit-config-pkg.yaml @@ -41,6 +41,7 @@ repos: data/.*| )$ - id: lintr + args: [--load_package] - id: readme-rmd-rendered - id: parsable-R - id: no-browser-statement diff --git a/tests/testthat/test-setup.R b/tests/testthat/test-setup.R index 18685bb79..0018acfc8 100644 --- a/tests/testthat/test-setup.R +++ b/tests/testthat/test-setup.R @@ -37,7 +37,14 @@ test_that("snippet generation works for lintr", { out <- capture_output(snippet_generate("additional-deps-lintr")), NA, ) - expect_equal(out, "") + expect_equal(out, paste0( + " - id: lintr\n", + " # lintr requires loading pkg -> add dependencies (incl. Suggests) from DESCRIPTION\n", + " args: [--load_package]\n", + " additional_dependencies:\n", + " - testthat\n", + "" + )) usethis::use_package("styler") expect_error( out <- capture_output(snippet_generate("additional-deps-lintr")),