diff --git a/DESCRIPTION b/DESCRIPTION index 44f7af4d09..4fb421eb2e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,6 @@ Imports: Suggests: bookdown, crayon, - fs, httr (>= 1.2.1), jsonlite, mockery, @@ -48,8 +47,8 @@ Suggests: testthat (>= 3.0.0), tibble, tufte, - usethis, - withr (>= 2.5.0) + withr (>= 2.5.0), + xfun VignetteBuilder: knitr Config/Needs/website: tidyverse/tidytemplate diff --git a/R/use_lintr.R b/R/use_lintr.R index 2586645d8c..7c3eb099d3 100644 --- a/R/use_lintr.R +++ b/R/use_lintr.R @@ -45,12 +45,30 @@ use_lintr <- function(path = ".", type = c("tidyverse", "full")) { write.dcf(the_config, config_file, width = Inf) # If this is an R package and if available, add .lintr file to .Rbuildignore - if (file.exists("DESCRIPTION")) { + if (file.exists("DESCRIPTION") && file.exists(".Rbuildignore")) { try( - usethis::use_build_ignore(fs::path_rel(config_file)), + add_build_ignore(config_file), silent = TRUE ) } invisible(config_file) } + +add_build_ignore <- function(path) { + path_build_ignore <- ".Rbuildignore" + existing_lines <- xfun::read_utf8(path_build_ignore) + + escape_path <- gsub("^\\./", "", path) + escape_path <- gsub("\\.", "\\\\.", escape_path) + escape_path <- gsub("/$", "", escape_path) + escape_path <- paste0("^", escape_path, "$") + + new_lines <- c(existing_lines, setdiff(escape_path, existing_lines)) + + xfun::write_utf8(new_lines, path_build_ignore) + + message("Add '", escape_path, "' to ", path_build_ignore) + + invisible(NULL) +}