@@ -237,71 +237,79 @@ upstream_repo_url_is_outdated <- function() {
237237# ' * additional-deps-roxygenize: Code to paste into
238238# ' `.pre-commit-config.yaml` for the additional dependencies required by
239239# ' the roxygenize hook.
240+ # ' * additional-deps-lintr: Code to paste into
241+ # ' `.pre-commit-config.yaml` for the additional dependencies required by
242+ # ' the lintr hook if you use `--load-package`.
240243# ' @param snippet Name of the snippet.
241244# ' @param open Whether or not to open the .pre-commit-config.yaml. The default
242245# ' is `TRUE` when working in RStudio. Otherwise, we recommend manually opening
243246# ' the file.
244247# ' @inheritParams fallback_doc
245248# ' @export
246- snippet_generate <- function (snippet = " " ,
249+ snippet_generate <- function (snippet = " additional-deps-roxygenize " ,
247250 open = rstudioapi :: isAvailable(),
248251 root = here :: here()) {
249- rlang :: arg_match(snippet , c(" additional-deps-roxygenize" ))
250- if (snippet == " additional-deps-roxygenize" ) {
251- rlang :: inform(paste(
252- " Generating snippet using CRAN versions. If you need another source," ,
253- " specify with syntax that `renv::install()` understands (see examples in" ,
254- " help file)." ,
255- " \n "
256- ))
257- deps <- desc :: desc_get_deps()
258- hard_dependencies <- deps [(deps $ type %in% c(" Depends" , " Imports" )), " package" ] %> %
259- setdiff(" R" )
260- if (length(hard_dependencies ) < 1 ) {
261- cli :: cli_alert_success(paste0(
262- " According to {.code DESCRIPTION}`, there are no hard dependencies of " ,
263- " your package. You are set."
264- ))
265- return ()
266- }
267- hard_dependencies %> %
268- snippet_generate_impl_additional_deps_roxygenize() %> %
269- cat(sep = " " )
270- cat(" \n " )
271- cli :: cli_ul(paste0(
272- " Replace the `id: roxygenize` key in `.pre-commit-config.yaml` with the " ,
273- " above code."
274- ))
275- cli :: cli_alert_info(paste0(
276- " Note that CI services like {.url pre-commit.ci} have build-time " ,
277- " restrictions and installing the above dependencies may exceed those, " ,
278- " resulting in a timeout. In addition, system dependencies are not " ,
279- " supported for {.url pre-commit.ci}. See " ,
280- ' {.code vignette("ci", package = "precommit")} for details and solutions.'
252+ snippet_generator <- if (snippet == ' additional-deps-roxygenize' ) {
253+ snippet_generate_impl_additional_deps_roxygenize
254+ } else if (snippet == ' additional-deps-lintr' ) {
255+ snippet_generate_impl_additional_deps_lintr
256+ } else {
257+ rlang :: abort(paste0(' Snippet "' , snippet , ' " not supported' ))
258+ }
259+ rlang :: inform(paste(
260+ " Generating snippet using CRAN versions. If you need another source," ,
261+ " specify with syntax that `renv::install()` understands (see examples in" ,
262+ " help file)." ,
263+ " \n "
264+ ))
265+ deps <- desc :: desc_get_deps()
266+ hard_dependencies <- deps [(deps $ type %in% c(" Depends" , " Imports" )), " package" ] %> %
267+ setdiff(" R" )
268+ if (length(hard_dependencies ) < 1 ) {
269+ cli :: cli_alert_success(paste0(
270+ " According to {.code DESCRIPTION}`, there are no hard dependencies of " ,
271+ " your package. You are set."
281272 ))
282- remote_deps <- rlang :: try_fetch(
283- desc :: desc_get_field(" Remotes" ),
284- error = function (e ) character ()
285- )
286- if (length(remote_deps ) > 0 ) {
287- rlang :: warn(paste0(
288- " It seems you have remote dependencies in your `DESCRIPTION`. You " ,
289- " need to edit the above list manually to match the syntax `renv::install()` " ,
290- " understands, i.e. if you have in your `DESCRIPTION`
273+ return ()
274+ }
275+
276+ hard_dependencies %> %
277+ snippet_generator() %> %
278+ cat(sep = " " )
279+ cat(" \n " )
280+ cli :: cli_ul(paste0(
281+ " Replace the `id: roxygenize` key in `.pre-commit-config.yaml` with the " ,
282+ " above code."
283+ ))
284+ cli :: cli_alert_info(paste0(
285+ " Note that CI services like {.url pre-commit.ci} have build-time " ,
286+ " restrictions and installing the above dependencies may exceed those, " ,
287+ " resulting in a timeout. In addition, system dependencies are not " ,
288+ " supported for {.url pre-commit.ci}. See " ,
289+ ' {.code vignette("ci", package = "precommit")} for details and solutions.'
290+ ))
291+ remote_deps <- rlang :: try_fetch(
292+ desc :: desc_get_field(" Remotes" ),
293+ error = function (e ) character ()
294+ )
295+ if (length(remote_deps ) > 0 ) {
296+ rlang :: warn(paste0(
297+ " It seems you have remote dependencies in your `DESCRIPTION`. You " ,
298+ " need to edit the above list manually to match the syntax `renv::install()` " ,
299+ " understands, i.e. if you have in your `DESCRIPTION`
291300
292301Imports:
293- tidyr
302+ tidyr
294303Remotes:
295- tidyverse/tidyr@2fd80d5
304+ tidyverse/tidyr@2fd80d5
296305
297306You need in your `.pre-commit-config.yaml`
298307
299- additional_dependencies:
300- - tidyverse/tidyr@2fd80d5
308+ additional_dependencies:
309+ - tidyverse/tidyr@2fd80d5
301310
302311"
303- ))
304- }
312+ ))
305313 }
306314 if (open ) {
307315 precommit :: open_config(root )
@@ -318,3 +326,14 @@ snippet_generate_impl_additional_deps_roxygenize <- function(packages, with_vers
318326 # roxygen requires loading pkg -> add dependencies from DESCRIPTION
319327 additional_dependencies:\n " , out )
320328}
329+
330+ snippet_generate_impl_additional_deps_lintr <- function (packages , with_version = FALSE ) {
331+ out <- paste0(
332+ " - " , packages , " \n " ,
333+ collapse = " "
334+ ) %> %
335+ sort()
336+ paste0(" - id: lintr
337+ # lintr requires loading pkg -> add dependencies from DESCRIPTION
338+ additional_dependencies:\n " , out )
339+ }
0 commit comments