Skip to content

Commit

Permalink
Rename files + add warn = FALSE
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed May 24, 2024
1 parent bfed992 commit 344bf4d
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/files-conflicts.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ solve_file_name_conflict <- function(files, regex, dir = ".", extra_msg = NULL,
}
bullets_df <-
rlang::set_names(files) |>
purrr::map(\(x) readLines(x, encoding = "UTF-8")) |>
purrr::map(\(x) readLines(x, encoding = "UTF-8", warn = FALSE)) |>
purrr::map(\(x) tibble::enframe(x, name = "line_number", value = "content")) |>
dplyr::bind_rows(.id = "file")

Expand Down Expand Up @@ -145,7 +145,7 @@ get_referenced_files <- function(files) {
# Create a list of genuine referenced files
# TODO Add false positive references
# TODO fs::path and file.path should be handled differently
purrr::map(files, \(x) readLines(x, encoding = "UTF-8")) |>
purrr::map(files, \(x) readLines(x, encoding = "UTF-8", warn = FALSE)) |>
purrr::list_c(ptype = "character") |>
stringr::str_subset(pattern = "\\:\\:dav.+lt|\\:\\:nw_|g.docs_l.n|target-|\\.0pt", negate = TRUE) |> # remove false positive from .md files
stringr::str_subset(pattern = "file.path|fs\\:\\:path\\(|path_package|system.file", negate = TRUE) |> # Exclude fs::path() and file.path from search since handled differently.
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion R/rename-files.R → R/rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rename_files2 <- function(old,
}

is_git <- !isFALSE(tryCatch(rprojroot::find_root_file(criterion = rprojroot::criteria$is_vcs_root), error = function(e) FALSE))
proj_name <- proj_get2()
if (interactive() && !is_git && !identical(Sys.getenv("TESTTHAT"), "true")) {
cli::cli_warn(c(
"It is better to use this function in a version-controlled repository.",
Expand All @@ -91,6 +92,8 @@ rename_files2 <- function(old,
related_files <- fs::dir_ls(regexp = paste0(basename_remove_ext(old), "\\."), recurse = TRUE)
related_files <- fs::path_filter(related_files, "_snaps/|_book/|_files|_freeze|renv/", invert = TRUE)
related_files <- setdiff(related_files, old)
# remove project name from conflicts.
related_files <- stringr::str_subset(related_files, proj_name, negate = TRUE)
if (length(related_files) > 0) {
# maybe would need to normalize path.
cli::cli_warn(c(
Expand Down Expand Up @@ -359,7 +362,7 @@ hint_acceptable_renaming <- function(old, new, overwrite) {
))
return(FALSE)
}
# r-lib/cli#683
# Delete when fixed r-lib/cli#683
old_chr <- as.character(old)
new_chr <- as.character(new)

Expand Down
2 changes: 1 addition & 1 deletion R/use-todo.R → R/todo.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ complete_todo <- function(line, file, regexp, rm_line = NULL) {
}
warn_change_of_line <- FALSE

file_content <- readLines(file, encoding = "UTF-8")
file_content <- readLines(file, encoding = "UTF-8", warn = FALSE)
line_content <- file_content[line]

# Special case for issues (probably need to opt out at some point)
Expand Down
1 change: 1 addition & 0 deletions TODO.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
# TODO [check_referenced_files] doesn't check for {.file R/file.R}
# TODO explain rationale behind `work_only`. Suggest to transform to TODO if this item is no longer critical. `work_only` goal is to show you exactly where you need to do work
# TODO [outline] Show function call if exported + not internal + bonus if has family tagf
# TODO rename_files should be less noisy about project name file
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ test_that("use_todo() global works", {
expect_no_error(
suppressMessages(path <- use_todo("global::it is time"))
)
line_to_delete <- length(readLines(path, encoding = "UTF-8"))
line_to_delete <- length(readLines(path, encoding = "UTF-8", warn = FALSE))
suppressMessages(complete_todo(file = path, regexp = "it is time", line = line_to_delete, rm_line = TRUE))
})

0 comments on commit 344bf4d

Please sign in to comment.