Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add .lintr to .Rbuildignore by the use_lintr function #1895

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Imports:
Suggests:
bookdown,
crayon,
fs,
httr (>= 1.2.1),
jsonlite,
mockery,
Expand All @@ -47,6 +48,7 @@ Suggests:
testthat (>= 3.1.5),
tibble,
tufte,
usethis,
withr (>= 2.5.0)
Enhances:
data.table
Expand Down
9 changes: 9 additions & 0 deletions R/use_lintr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 14 additions & 0 deletions tests/testthat/test-use_lintr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})