Skip to content

Commit 1aa1ff5

Browse files
committed
Update lintr hook and snippet_generate for lintr hook
1 parent 377f43e commit 1aa1ff5

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: precommit
22
Title: Pre-Commit Hooks
3-
Version: 0.4.3.9018
3+
Version: 0.4.3.9019
44
Author: Lorenz Walthert
55
Maintainer: Lorenz Walthert <[email protected]>
66
Description: Useful git hooks for R building on top of the multi-language

R/setup.R

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ use_ci <- function(ci = getOption("precommit.ci", "native"),
133133
"proceed."
134134
))
135135
}
136+
137+
if (length(grep("^ *- *id *: *lintr", config)) > 0) {
138+
cli::cli_ul(paste0(
139+
"It seems like you are using the lintr hook. This requires further ",
140+
"edits in your {.code .pre-commit-config.yaml}, please run ",
141+
"{.code precommit::snippet_generate('additional-deps-lintr')} to ",
142+
"proceed."
143+
))
144+
}
136145
}
137146

138147
#' Auto-update your hooks
@@ -263,8 +272,17 @@ snippet_generate <- function(snippet = "additional-deps-roxygenize",
263272
"\n"
264273
))
265274
deps <- desc::desc_get_deps()
266-
hard_dependencies <- deps[(deps$type %in% c("Depends", "Imports")), "package"] %>%
275+
276+
# Add Suggests for lintr, so it works on vignettes, readme, etc.
277+
dep_types <- if (snippet == "additional-deps-lintr") {
278+
c("Depends", "Imports", "Suggests")
279+
} else {
280+
c("Depends", "Imports")
281+
}
282+
283+
hard_dependencies <- deps[(deps$type %in% dep_types), "package"] %>%
267284
setdiff("R")
285+
268286
if (length(hard_dependencies) < 1) {
269287
cli::cli_alert_success(paste0(
270288
"According to {.code DESCRIPTION}`, there are no hard dependencies of ",
@@ -277,10 +295,7 @@ snippet_generate <- function(snippet = "additional-deps-roxygenize",
277295
snippet_generator() %>%
278296
cat(sep = "")
279297
cat("\n")
280-
cli::cli_ul(paste0(
281-
"Replace the `id: roxygenize` key in `.pre-commit-config.yaml` with the ",
282-
"above code."
283-
))
298+
284299
cli::cli_alert_info(paste0(
285300
"Note that CI services like {.url pre-commit.ci} have build-time ",
286301
"restrictions and installing the above dependencies may exceed those, ",
@@ -334,6 +349,6 @@ snippet_generate_impl_additional_deps_lintr <- function(packages, with_version =
334349
) %>%
335350
sort()
336351
paste0(" - id: lintr
337-
# lintr requires loading pkg -> add dependencies from DESCRIPTION
352+
# lintr requires loading pkg -> add dependencies (incl. Suggests) from DESCRIPTION
338353
additional_dependencies:\n", out)
339354
}

tests/testthat/test-setup.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ test_that("snippet generation works for lintr", {
3737
out <- capture_output(snippet_generate("additional-deps-lintr")),
3838
NA,
3939
)
40-
expect_equal(out, "")
40+
expect_equal(out, paste0(
41+
" - id: lintr\n",
42+
" # lintr requires loading pkg -> add dependencies (incl. Suggests) from DESCRIPTION\n",
43+
" additional_dependencies:\n",
44+
" - testthat\n",
45+
""
46+
))
4147
usethis::use_package("styler")
4248
expect_error(
4349
out <- capture_output(snippet_generate("additional-deps-lintr")),

0 commit comments

Comments
 (0)