diff --git a/DESCRIPTION b/DESCRIPTION index 10e5d5984..aba727173 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,6 +37,7 @@ Imports: Suggests: bookdown, crayon, + fs, httr (>= 1.2.1), jsonlite, mockery, @@ -47,6 +48,7 @@ Suggests: testthat (>= 3.1.5), tibble, tufte, + usethis, withr (>= 2.5.0) Enhances: data.table diff --git a/R/use_lintr.R b/R/use_lintr.R index 2a40311c4..2586645d8 100644 --- a/R/use_lintr.R +++ b/R/use_lintr.R @@ -43,5 +43,14 @@ 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")) { + try( + usethis::use_build_ignore(fs::path_rel(config_file)), + silent = TRUE + ) + } + invisible(config_file) } diff --git a/tests/testthat/test-use_lintr.R b/tests/testthat/test-use_lintr.R index 68e089322..2dc9aefeb 100644 --- a/tests/testthat/test-use_lintr.R +++ b/tests/testthat/test-use_lintr.R @@ -35,3 +35,17 @@ test_that("use_lintr with type = full also works", { lints <- lint_dir(tmp) expect_length(lints, 0L) }) + +test_that("use_lintr add .lintr to .Rbuildignore for packages", { + tmp <- withr::local_tempdir() + tmp_package_dir <- paste0(tmp, "/package") + package_dir <- test_path("dummy_packages", "package") + dir.create(tmp_package_dir) + file.copy(package_dir, tmp, recursive = TRUE) + setwd(tmp_package_dir) + lintr_file <- use_lintr() + expect_true(file.exists(lintr_file)) + + skip_if_not_installed("usethis") + expect_true("^\\.lintr$" %in% readLines(".Rbuildignore")) +})