From e20b398f9d507c328cc5fdf57bbc90d1bec2fd17 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Sun, 8 Jan 2023 03:50:59 +0000 Subject: [PATCH 01/12] add usethis to Suggests --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 81bac559f..001e0517a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -47,6 +47,7 @@ Suggests: testthat (>= 3.0.0), tibble, tufte, + usethis, withr (>= 2.5.0) VignetteBuilder: knitr From e89ca5d42e7df188bb1698a19bd6fba4686ee513 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Sun, 8 Jan 2023 04:06:49 +0000 Subject: [PATCH 02/12] add fs to Suggests --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 001e0517a..44f7af4d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,6 +37,7 @@ Imports: Suggests: bookdown, crayon, + fs, httr (>= 1.2.1), jsonlite, mockery, From 29b8ebf6bdd8a164740006ea512a5b9fdb9f16cb Mon Sep 17 00:00:00 2001 From: eitsupi Date: Sun, 8 Jan 2023 04:30:10 +0000 Subject: [PATCH 03/12] If available, add .lintr file path to .Rbuildignore --- R/use_lintr.R | 9 +++++++++ 1 file changed, 9 insertions(+) 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) } From 780cb2b789043d1219c2fbe762411b3d4fb405fa Mon Sep 17 00:00:00 2001 From: eitsupi Date: Sun, 8 Jan 2023 04:55:12 +0000 Subject: [PATCH 04/12] add test --- tests/testthat/test-use_lintr.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/testthat/test-use_lintr.R b/tests/testthat/test-use_lintr.R index 68e089322..b6a97394a 100644 --- a/tests/testthat/test-use_lintr.R +++ b/tests/testthat/test-use_lintr.R @@ -35,3 +35,14 @@ 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", { + skip_if_not_installed("usethis") + + tmp <- withr::local_tempdir() + usethis::create_package(tmp) + setwd(tmp) + lintr_file <- use_lintr() + expect_true(file.exists(lintr_file)) + expect_true("^\\.lintr$" %in% readLines(".Rbuildignore")) +}) From a9e8be39d4a2a59e86dbfb180fbc33853d9a321c Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 04:11:37 +0000 Subject: [PATCH 05/12] update test for not to use usethis --- tests/testthat/test-use_lintr.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-use_lintr.R b/tests/testthat/test-use_lintr.R index b6a97394a..db4eb7b60 100644 --- a/tests/testthat/test-use_lintr.R +++ b/tests/testthat/test-use_lintr.R @@ -37,11 +37,12 @@ test_that("use_lintr with type = full also works", { }) test_that("use_lintr add .lintr to .Rbuildignore for packages", { - skip_if_not_installed("usethis") - tmp <- withr::local_tempdir() - usethis::create_package(tmp) - setwd(tmp) + 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)) expect_true("^\\.lintr$" %in% readLines(".Rbuildignore")) From efe56d112669def0d3fdef13c8ceefd3169b2d1b Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 06:00:55 +0000 Subject: [PATCH 06/12] remove usethis and fs functions --- DESCRIPTION | 5 ++--- R/use_lintr.R | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 44f7af4d0..4fb421eb2 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 2586645d8..b33457eaa 100644 --- a/R/use_lintr.R +++ b/R/use_lintr.R @@ -45,12 +45,27 @@ 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 <- file.path(".", ".Rbuildignore") + existing_lines <- xfun::read_utf8(path_build_ignore) + + escape_path <- rex::rex(start, rex::re_substitutes(path, list(start, "./") %or% list("/", end), ""), end) + + 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) +} From b0f93e33c50e593fcdf3f7d519b313ffef4df232 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 06:16:37 +0000 Subject: [PATCH 07/12] fix test --- tests/testthat/_snaps/use_lintr.md | 9 +++++++++ tests/testthat/test-use_lintr.R | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/_snaps/use_lintr.md diff --git a/tests/testthat/_snaps/use_lintr.md b/tests/testthat/_snaps/use_lintr.md new file mode 100644 index 000000000..986f7c96b --- /dev/null +++ b/tests/testthat/_snaps/use_lintr.md @@ -0,0 +1,9 @@ +# use_lintr add .lintr to .Rbuildignore for packages + + Code + cat(brio::read_file(file.path(tmp_package_dir, ".Rbuildignore"))) + Output + ^lintr\.Rproj$ + ^\.Rproj\.user$ + ^\.lintr$ + diff --git a/tests/testthat/test-use_lintr.R b/tests/testthat/test-use_lintr.R index db4eb7b60..a93227c0d 100644 --- a/tests/testthat/test-use_lintr.R +++ b/tests/testthat/test-use_lintr.R @@ -45,5 +45,5 @@ test_that("use_lintr add .lintr to .Rbuildignore for packages", { setwd(tmp_package_dir) lintr_file <- use_lintr() expect_true(file.exists(lintr_file)) - expect_true("^\\.lintr$" %in% readLines(".Rbuildignore")) + expect_snapshot(cat(brio::read_file(file.path(tmp_package_dir, ".Rbuildignore")))) }) From 465a5b2e59cf127cefbd224378be08f87854f27e Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 06:24:15 +0000 Subject: [PATCH 08/12] fix --- R/use_lintr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/use_lintr.R b/R/use_lintr.R index b33457eaa..affe20d28 100644 --- a/R/use_lintr.R +++ b/R/use_lintr.R @@ -45,7 +45,7 @@ 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") && file.exists(".Rbuildignore")) { + if (file.exists("DESCRIPTION")) { try( add_build_ignore(config_file), silent = TRUE From b83f045f420c8324d7ddb67673817209ab109209 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 06:34:42 +0000 Subject: [PATCH 09/12] Revert "fix" This reverts commit 465a5b2e59cf127cefbd224378be08f87854f27e. --- R/use_lintr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/use_lintr.R b/R/use_lintr.R index affe20d28..b33457eaa 100644 --- a/R/use_lintr.R +++ b/R/use_lintr.R @@ -45,7 +45,7 @@ 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( add_build_ignore(config_file), silent = TRUE From 589e5266cd36d902d93964aaa41979a32b4e5e2b Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 06:34:54 +0000 Subject: [PATCH 10/12] Revert "fix test" This reverts commit b0f93e33c50e593fcdf3f7d519b313ffef4df232. --- tests/testthat/_snaps/use_lintr.md | 9 --------- tests/testthat/test-use_lintr.R | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 tests/testthat/_snaps/use_lintr.md diff --git a/tests/testthat/_snaps/use_lintr.md b/tests/testthat/_snaps/use_lintr.md deleted file mode 100644 index 986f7c96b..000000000 --- a/tests/testthat/_snaps/use_lintr.md +++ /dev/null @@ -1,9 +0,0 @@ -# use_lintr add .lintr to .Rbuildignore for packages - - Code - cat(brio::read_file(file.path(tmp_package_dir, ".Rbuildignore"))) - Output - ^lintr\.Rproj$ - ^\.Rproj\.user$ - ^\.lintr$ - diff --git a/tests/testthat/test-use_lintr.R b/tests/testthat/test-use_lintr.R index a93227c0d..db4eb7b60 100644 --- a/tests/testthat/test-use_lintr.R +++ b/tests/testthat/test-use_lintr.R @@ -45,5 +45,5 @@ test_that("use_lintr add .lintr to .Rbuildignore for packages", { setwd(tmp_package_dir) lintr_file <- use_lintr() expect_true(file.exists(lintr_file)) - expect_snapshot(cat(brio::read_file(file.path(tmp_package_dir, ".Rbuildignore")))) + expect_true("^\\.lintr$" %in% readLines(".Rbuildignore")) }) From b496bfb99726503cb36a952bf307ff8e82f2b972 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 06:36:08 +0000 Subject: [PATCH 11/12] Revert "remove usethis and fs functions" This reverts commit efe56d112669def0d3fdef13c8ceefd3169b2d1b. --- DESCRIPTION | 5 +++-- R/use_lintr.R | 19 ++----------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4fb421eb2..44f7af4d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,6 +37,7 @@ Imports: Suggests: bookdown, crayon, + fs, httr (>= 1.2.1), jsonlite, mockery, @@ -47,8 +48,8 @@ Suggests: testthat (>= 3.0.0), tibble, tufte, - withr (>= 2.5.0), - xfun + usethis, + withr (>= 2.5.0) VignetteBuilder: knitr Config/Needs/website: tidyverse/tidytemplate diff --git a/R/use_lintr.R b/R/use_lintr.R index b33457eaa..2586645d8 100644 --- a/R/use_lintr.R +++ b/R/use_lintr.R @@ -45,27 +45,12 @@ 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") && file.exists(".Rbuildignore")) { + if (file.exists("DESCRIPTION")) { try( - add_build_ignore(config_file), + usethis::use_build_ignore(fs::path_rel(config_file)), silent = TRUE ) } invisible(config_file) } - -add_build_ignore <- function(path) { - path_build_ignore <- file.path(".", ".Rbuildignore") - existing_lines <- xfun::read_utf8(path_build_ignore) - - escape_path <- rex::rex(start, rex::re_substitutes(path, list(start, "./") %or% list("/", end), ""), end) - - 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) -} From 9bbfb99c43ffaadbeb3c1881c331aaed41472b6f Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 9 Jan 2023 06:37:13 +0000 Subject: [PATCH 12/12] fix test --- tests/testthat/test-use_lintr.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-use_lintr.R b/tests/testthat/test-use_lintr.R index db4eb7b60..2dc9aefeb 100644 --- a/tests/testthat/test-use_lintr.R +++ b/tests/testthat/test-use_lintr.R @@ -45,5 +45,7 @@ test_that("use_lintr add .lintr to .Rbuildignore for packages", { 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")) })