Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Description: Useful git hooks for R building on top of the multi-language
Expand Down
28 changes: 22 additions & 6 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ",
Expand All @@ -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, ",
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions inst/pre-commit-config-pkg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ repos:
data/.*|
)$
- id: lintr
args: [--load_package]
- id: readme-rmd-rendered
- id: parsable-R
- id: no-browser-statement
Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down