Skip to content

Commit bfed992

Browse files
committed
Change line_id to line
1 parent e24af26 commit bfed992

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

R/outline-criteria.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ define_outline_criteria <- function(.data, print_todo) {
158158
)
159159
x <- dplyr::mutate(
160160
x,
161-
before_and_after_empty = line_id == 1 | !nzchar(dplyr::lead(content, default = "")) & !nzchar(dplyr::lag(content)),
161+
before_and_after_empty = line == 1 | !nzchar(dplyr::lead(content, default = "")) & !nzchar(dplyr::lag(content)),
162162
.by = file
163163
)
164164
x

R/outline.R

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ file_outline <- function(pattern = NULL,
122122
file_content <- rlang::set_names(path)
123123
# Not warn
124124
file_content <- purrr::map(file_content, function(x) readLines(fs::path_real(x), encoding = "UTF-8", warn = FALSE))
125-
# Combine everything into a tibble that contains file, line_id, content
126-
file_content <- purrr::map(file_content, function(x) tibble::enframe(x, name = "line_id", value = "content"))
125+
# Combine everything into a tibble that contains file, line, content
126+
file_content <- purrr::map(file_content, function(x) tibble::enframe(x, name = "line", value = "content"))
127127
file_content <- dplyr::bind_rows(file_content, .id = "file")
128128
} else {
129129
file_content <-
130130
purrr::map(
131131
.x = list("unsaved-doc.R" = rstudioapi::getSourceEditorContext()$contents),
132-
.f = function(x) tibble::enframe(x, name = "line_id", value = "content")
132+
.f = function(x) tibble::enframe(x, name = "line", value = "content")
133133
)
134134
file_content <- dplyr::bind_rows(file_content, .id = "file")
135135
}
@@ -365,7 +365,7 @@ print.outline_report <- function(x, ...) {
365365
link = list(rlang::set_names(
366366
link_rs_api,
367367
purrr::map_chr(
368-
paste0("{.file ", file, ":", line_id, "}"),
368+
paste0("{.file ", file, ":", line, "}"),
369369
cli::format_inline
370370
)
371371
)),
@@ -507,19 +507,19 @@ display_outline_element <- function(.data) {
507507
y <- dplyr::mutate(
508508
x,
509509
has_title_el =
510-
((line_id == 1 & !is_todo_fixme & !is_test_name & !is_snap_file) |
510+
((line == 1 & !is_todo_fixme & !is_test_name & !is_snap_file) |
511511
(is_doc_title & !is_subtitle & !is_snap_file & !is_second_level_heading_or_more)) & !is_news,
512512
.by = "file"
513513
)
514514
y <- withCallingHandlers(
515515
dplyr::mutate(y,
516-
title_el_line = ifelse(has_title_el, line_id[
517-
(line_id == 1 & !is_todo_fixme & !is_test_name & !is_snap_file) |
516+
title_el_line = ifelse(has_title_el, line[
517+
(line == 1 & !is_todo_fixme & !is_test_name & !is_snap_file) |
518518
(is_doc_title & !is_subtitle & !is_snap_file & !is_second_level_heading_or_more)
519519
][1], # take the first element to avoid problems (may be the reason why problems occur)
520520
NA_integer_
521521
),
522-
title_el = outline_el[line_id == title_el_line],
522+
title_el = outline_el[line == title_el_line],
523523
.by = "file"
524524
),
525525
error = function(e) {
@@ -529,7 +529,7 @@ display_outline_element <- function(.data) {
529529
)
530530
y <- dplyr::relocate(
531531
y,
532-
"outline_el", "line_id", "title_el", "title_el_line", "has_title_el",
532+
"outline_el", "line", "title_el", "title_el_line", "has_title_el",
533533
.after = "content"
534534
)
535535

@@ -595,7 +595,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
595595
as.character(trim_outline(.data$outline_el[cn], width - 8L)),
596596
"- {.run [Done{cli::symbol$tick}?](reuseme::complete_todo(",
597597
# Removed ending dot. (possibly will fail with older versions)
598-
.data$line_id[cn], ", '", .data$file[cn], "', '",
598+
.data$line[cn], ", '", .data$file[cn], "', '",
599599
# modify regex twice if needed (see below)
600600
stringr::str_sub(stringr::str_replace_all(.data$content[cn], "\\^|\\$|'|\\{|\\}|\\)|\\(|\\[\\]|\\+", "."), start = -15L), "'))}",
601601
.data$rs_version[cn]
@@ -617,7 +617,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
617617
# Removed ending dot. (possibly will fail with older versions)
618618

619619
# modify regex twice if needed (see above)
620-
line_id, ", '", file, "', '", stringr::str_sub(stringr::str_replace_all(content, "\\^|\\$|'|\\{|\\}|\\)|\\(|\\[\\]|\\+", "."), start = -15L), "'))}",
620+
line, ", '", file, "', '", stringr::str_sub(stringr::str_replace_all(content, "\\^|\\$|'|\\{|\\}|\\)|\\(|\\[\\]|\\+", "."), start = -15L), "'))}",
621621
rs_version
622622
),
623623
outline_el2
@@ -626,7 +626,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
626626
)
627627

628628
.data <- dplyr::mutate(.data,
629-
link = paste0(outline_el2, " {.path ", file, ":", line_id, "}"),
629+
link = paste0(outline_el2, " {.path ", file, ":", line, "}"),
630630
# rstudioapi::documentOpen works in the visual mode!! but not fully.
631631
file_path = .data$file,
632632
is_saved_doc = .env$is_saved_doc,
@@ -646,15 +646,15 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
646646
}
647647

648648
dplyr::mutate(.data,
649-
# link_rs_api = paste0("{.run [", outline_el, "](reuseme::open_rs_doc('", file_path, "', line = ", line_id, "))}"),
649+
# link_rs_api = paste0("{.run [", outline_el, "](reuseme::open_rs_doc('", file_path, "', line = ", line, "))}"),
650650
link_rs_api = dplyr::case_when(
651651
is.na(outline_el2) ~ NA_character_,
652-
!is_saved_doc ~ paste0("line ", line_id, " -", outline_el2),
652+
!is_saved_doc ~ paste0("line ", line, " -", outline_el2),
653653
rs_avail_file_link ~ paste0(
654654
"{cli::style_hyperlink(", style_fun, ', "',
655-
paste0("file://", file_path), '", params = list(line = ', line_id, ", col = 1))} ", outline_el2
655+
paste0("file://", file_path), '", params = list(line = ', line, ", col = 1))} ", outline_el2
656656
),
657-
.default = paste0(rs_version, "{.run [i](reuseme::open_rs_doc('", file_path, "', line = ", line_id, "))} ", outline_el2)
657+
.default = paste0(rs_version, "{.run [i](reuseme::open_rs_doc('", file_path, "', line = ", line, "))} ", outline_el2)
658658
),
659659
file_hl = dplyr::case_when(
660660
!is_saved_doc ~ file_path,

R/use-todo.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use_todo <- function(todo, proj = proj_get2(), code = FALSE) {
6666
#' Function meant to be wrapped as `{.run}` hyperlinks with [file_outline()].
6767
#' It basically removes a line from a file.
6868
#'
69-
#' @param line_id The line number (a single integer)
69+
#' @param line The line number (a single integer)
7070
#' @param file Path to a file
7171
#' @param regexp A regexp to assess that the file content has not changed.
7272
#' @param rm_line A logical If `NULL` will remove the full line in the file
@@ -77,18 +77,18 @@ use_todo <- function(todo, proj = proj_get2(), code = FALSE) {
7777
#' content invisibly.
7878
#' @export
7979
#' @keywords internal
80-
complete_todo <- function(line_id, file, regexp, rm_line = NULL) {
80+
complete_todo <- function(line, file, regexp, rm_line = NULL) {
8181
check_string(regexp)
82-
check_number_whole(line_id)
83-
line_id_original <- line_id
82+
check_number_whole(line)
83+
line_original <- line
8484
# to defer warning.
8585
if (interactive() && rstudioapi::isAvailable()) {
8686
rstudioapi::documentSaveAll()
8787
}
8888
warn_change_of_line <- FALSE
8989

9090
file_content <- readLines(file, encoding = "UTF-8")
91-
line_content <- file_content[line_id]
91+
line_content <- file_content[line]
9292

9393
# Special case for issues (probably need to opt out at some point)
9494
# patch that will likely not work for many cases.
@@ -105,8 +105,8 @@ complete_todo <- function(line_id, file, regexp, rm_line = NULL) {
105105
warn_change_of_line <- TRUE
106106

107107
if (length(regexp_detection) == 1) {
108-
line_id <- regexp_detection
109-
line_content <- line_content <- file_content[line_id]
108+
line <- regexp_detection
109+
line_content <- line_content <- file_content[line]
110110
detect_regexp_in_line <- grepl(pattern = regexp, x = line_content)
111111
} else if (length(regexp_detection) > 1) {
112112
cli::cli_abort(c(
@@ -121,12 +121,12 @@ complete_todo <- function(line_id, file, regexp, rm_line = NULL) {
121121
}
122122
}
123123

124-
tag_type <- extract_tag_in_text(text = line_content, line_id)
124+
tag_type <- extract_tag_in_text(text = line_content, line)
125125

126126
if (warn_change_of_line) {
127127
cli::cli_warn(c(
128128
x = "Could not find {.arg regexp} as expected",
129-
"Could not find {.val {regexp}} at line {line_id_original}.",
129+
"Could not find {.val {regexp}} at line {line_original}.",
130130
i = "Has the file content changed since you ran this code?",
131131
# needs qty for cli pluralization, but no printing
132132
"`regexp` was detected in {cli::qty(length(regexp_detection))} line{?s} {regexp_detection}."
@@ -152,18 +152,18 @@ complete_todo <- function(line_id, file, regexp, rm_line = NULL) {
152152
regex_new <- cli::style_strikethrough(regex)
153153
line_content_show <- stringr::str_replace(line_content_show, regex, regex_new)
154154
}
155-
file_line <- paste0(file, ":", line_id)
155+
file_line <- paste0(file, ":", line)
156156
cli::cli_alert_success(
157157
"Removed {.code {line_content_show}} from {.file {file_line}}!"
158158
)
159159
# Rem
160160
line_content_new <- strip_todo_line(line_content, only_rm_tag = !rm_line)
161161

162162
if (nzchar(line_content_new)) {
163-
file_content[line_id] <- line_content_new
163+
file_content[line] <- line_content_new
164164
file_content_new <- file_content
165165
} else {
166-
file_content_new <- file_content[-line_id]
166+
file_content_new <- file_content[-line]
167167
if (!rm_line) {
168168
# WIll remove this line eventually
169169
# remove line if it ends up empty. not supposed to happen

man/complete_todo.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/use-todo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Marking a TODO item as done works
22

33
Code
4-
complete_todo(line_id = 1, file = tmp, regexp = "I Want this done")
4+
complete_todo(line = 1, file = tmp, regexp = "I Want this done")
55
Condition
66
Error in `complete_todo()`:
77
x Could not delete the TODO item.
88
i Line 1 does not contain any "WORK", "FIXME", or "TODO" tags.
99
Code
10-
complete_todo(line_id = 2, file = tmp)
10+
complete_todo(line = 2, file = tmp)
1111
Condition
1212
Error in `complete_todo()`:
1313
! `regexp` must be a single string, not absent.

tests/testthat/test-use-todo.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ test_that("Marking a TODO item as done works", {
4646
# tmp still has 7 lines
4747
expect_snapshot(error = TRUE, {
4848
# Can't delete the first line as it doesn't contain a TODO item
49-
complete_todo(line_id = 1, file = tmp, regexp = "I Want this done")
49+
complete_todo(line = 1, file = tmp, regexp = "I Want this done")
5050
# Try to delete TODO item at line 2 without providing the regexp for safeguard
51-
complete_todo(line_id = 2, file = tmp)
51+
complete_todo(line = 2, file = tmp)
5252
})
5353
# Deleting the TODO item line completely (tmp now has 4 lines)
5454
expect_complete_todo(
55-
complete_todo(line_id = 2, file = tmp, regexp = "item to delete")
55+
complete_todo(line = 2, file = tmp, regexp = "item to delete")
5656
)
5757
# Deleting the work tag (on new line 2), but keeping the comment.
5858
# Will throw a warning for now.
5959

6060
expect_complete_todo(
6161
out <- complete_todo(
62-
line_id = 4,
62+
line = 4,
6363
file = tmp,
6464
regexp = "Explain what the next code does"
6565
),
@@ -71,7 +71,7 @@ test_that("Marking a TODO item as done works", {
7171
)
7272
expect_complete_todo(
7373
out <- complete_todo(
74-
line_id = 4,
74+
line = 4,
7575
file = tmp,
7676
regexp = "ethisissues1890"
7777
),
@@ -101,5 +101,5 @@ test_that("use_todo() global works", {
101101
suppressMessages(path <- use_todo("global::it is time"))
102102
)
103103
line_to_delete <- length(readLines(path, encoding = "UTF-8"))
104-
suppressMessages(complete_todo(file = path, regexp = "it is time", line_id = line_to_delete, rm_line = TRUE))
104+
suppressMessages(complete_todo(file = path, regexp = "it is time", line = line_to_delete, rm_line = TRUE))
105105
})

0 commit comments

Comments
 (0)