Skip to content

Commit

Permalink
Remove work_only
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Jun 8, 2024
1 parent 70ed022 commit 39385e5
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 95 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ Suggests:
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1.9000
RoxygenNote: 7.3.1
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* If you previously relied on specifying pattern without naming it, you will have
to get used to the opposite. Naming `pattern`, but not path.

* Removed `work_only` argument from `file_outline()`, use `pattern = "WORK"` to
acheive the same result.

## Fixes

* `file_outline()` now recognize `describe()` test calls.
Expand Down
9 changes: 0 additions & 9 deletions R/outline-criteria.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ o_is_todo_fixme <- function(x, is_roxygen_comment = FALSE) {
has_todo
}

o_is_work_item <- function(x, is_roxygen_comment = FALSE) {
res <- stringr::str_detect(x, "(?<!\")# WORK")
if (!any(res)) {
return(res)
}
res[which(res)] <- o_is_todo_fixme(x[which(res)], is_roxygen_comment)
res
}

o_is_test_name <- function(x) {
# avoid generic like f works.
potential_test <- grepl("{", x, fixed = TRUE)
Expand Down
48 changes: 10 additions & 38 deletions R/outline.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#' * Colored output for
#' * URL and gh issue detection and link creation.
#'
#'
#' If `work_only` is set to `TRUE`, the function will only return outline of the `# WORK` comment
#' in `path`. `work_only = TRUE` will have an effect on `pattern`.
#'
#' By default
#' * `file_outline()` prints the outline the [active document][active_rs_doc()] if in RStudio
#' * `proj_outline()` prints the outline of the [active project][usethis::proj_get()] if in RStudio
Expand All @@ -46,9 +42,6 @@
#' @param pattern A string or regex to search for in the outline. If
#' specified, will search only for elements matching this regular expression.
#' The print method will show the document title for context. Previously `regex_outline`
#' @param work_only If `TRUE`, (the default), will only show you work items
#' first. Set to `FALSE` if you want to see the full outline. `WORK` will
#' combine with `pattern`
#' @param print_todo Should include TODOs in the file outline? If `FALSE`, will
#' print a less verbose output with sections.
#' @param alpha Whether to show in alphabetical order
Expand All @@ -64,13 +57,13 @@
#' @name outline
#' @examples
#' file <- fs::path_package("reuseme", "example-file", "outline-script.R")
#' file_outline(path = file)
#' file_outline(file)
#'
#' # Remove todo items
#' file_outline(path = file, print_todo = FALSE, alpha = TRUE)
#' file_outline(file, print_todo = FALSE, alpha = TRUE)
#'
#' # interact with data frame
#' file_outline(path = file) |> dplyr::as_tibble()
#' file_outline(file) |> dplyr::as_tibble()
#'
#' @examplesIf interactive()
#' # These all work on the active file / project or directory.
Expand All @@ -86,11 +79,10 @@ NULL
#' @rdname outline
file_outline <- function(path = active_rs_doc(),
pattern = NULL,
work_only = TRUE,
alpha = FALSE,
dir_common = NULL,
print_todo = TRUE,
recent_only = FALSE) {
recent_only = FALSE,
dir_common = NULL) {
# To contribute to this function, take a look at .github/CONTRIBUTING

if (length(path) == 1L && rlang::is_interactive() && is_rstudio()) {
Expand Down Expand Up @@ -144,26 +136,8 @@ file_outline <- function(path = active_rs_doc(),
)
)
# After this point we have validated that paths exist.

# Handle differently if in showing work items only
if (work_only) {
# Detect special tag for work item
should_show_only_work_items <- any(o_is_work_item(file_content$content))
# Check if there are work items in files
} else {
should_show_only_work_items <- FALSE
}

# Will append Work to the regexp outline, if it was provided.
# otherwise sets pattern to anything
if (should_show_only_work_items) {
cli::cli_inform("Use {.code work_only = FALSE} to display the full file/project outline.")
pattern <- paste(c("work\\s", pattern), collapse = "|")
} else {
pattern <- pattern %||% ".+"
}

check_string(pattern, arg = "You may have specified path Internal error")
pattern <- pattern %||% ".+"
check_string(pattern)

file_sections00 <- define_outline_criteria(file_content, print_todo = print_todo)

Expand Down Expand Up @@ -236,13 +210,12 @@ file_outline <- function(path = active_rs_doc(),
}
#' @rdname outline
#' @export
proj_outline <- function(proj = proj_get2(), pattern = NULL, work_only = TRUE, dir_tree = FALSE, alpha = FALSE, recent_only = FALSE) {
proj_outline <- function(proj = proj_get2(), pattern = NULL, dir_tree = FALSE, alpha = FALSE, recent_only = FALSE) {
is_active_proj <- identical(proj, proj_get2())

if (is_active_proj) {
return(dir_outline(
pattern = pattern,
work_only = work_only,
dir_tree = dir_tree,
alpha = alpha,
recent_only = recent_only,
Expand Down Expand Up @@ -281,15 +254,14 @@ proj_outline <- function(proj = proj_get2(), pattern = NULL, work_only = TRUE, d
dir_outline(
pattern = pattern,
path = proj_dir,
work_only = work_only,
dir_tree = dir_tree,
alpha = alpha,
recurse = TRUE
)
}
#' @rdname outline
#' @export
dir_outline <- function(path = ".", pattern = NULL, work_only = TRUE, dir_tree = FALSE, alpha = FALSE, recent_only = FALSE, recurse = FALSE) {
dir_outline <- function(path = ".", pattern = NULL, dir_tree = FALSE, alpha = FALSE, recent_only = FALSE, recurse = FALSE) {
dir <- fs::path_real(path)
file_exts <- c("R", "qmd", "Rmd", "md", "Rmarkdown")
file_exts_regex <- paste0("*.", file_exts, "$", collapse = "|")
Expand Down Expand Up @@ -325,7 +297,7 @@ dir_outline <- function(path = ".", pattern = NULL, work_only = TRUE, dir_tree =
invert = TRUE
)
}
file_outline(path = file_list_to_outline, pattern = pattern, work_only = work_only, dir_common = dir, alpha = alpha, recent_only = recent_only)
file_outline(path = file_list_to_outline, pattern = pattern, dir_common = dir, alpha = alpha, recent_only = recent_only)
}

exclude_example_files <- function(path) {
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ bench::mark(
#> # A tibble: 1 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 outline <- proj_outline() 463ms 473ms 2.12 22.3MB 4.23
#> 1 outline <- proj_outline() 874ms 874ms 1.14 22.2MB 2.29
```

<details>
Expand Down Expand Up @@ -313,7 +313,7 @@ outline
#>
#> ── `tests/testthat/_snaps/outline.md`
#> `i` file_outline() works
#> `i` alpha and work_only arguments work
#> `i` alpha arguments works
#> `i` file_outline() is a data frame
#> `i` pattern works as expected
#> `i` file_outline() detects correctly knitr notebooks
Expand Down Expand Up @@ -374,7 +374,6 @@ outline
#> `i` No outline criteria are untested
#>
#> ── `tests/testthat/test-outline.R`
#> `i` alpha and work_only arguments work
#> `i` file_outline() is a data frame
#> `i` TODO change tests for data frame size when stable (efficiency). As still debugging, better to keep all snapshots.
#> `i` file_outline() with only title doesn't error
Expand Down Expand Up @@ -414,7 +413,6 @@ outline
#> `i` TODO delete generated files
#> `i` TODO [proj_file] to accesss data (return the path in this case?)
#> `i` TODO [check_referenced_files] doesn't check for 'R/file.R'
#> `i` 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
#> `i` TODO browse_pkg should open by default if no vignettes are found, because there is not much to do in the R-session.
#> `i` TODO exclude _files from `proj_list()`
#> `i` TODO rename_files should be less noisy about project name file
Expand Down
1 change: 0 additions & 1 deletion TODO.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# TODO [delete] generated files
# TODO [proj_file] to accesss data (return the path in this case?)
# 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 browse_pkg should open by default if no vignettes are found, because there is not much to do in the R-session.
# TODO exclude _files from `proj_list()`
# TODO rename_files should be less noisy about project name file
Expand Down
24 changes: 7 additions & 17 deletions man/outline.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/testthat/_snaps/outline-criteria.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
o_is_tab_plot_title
o_is_test_name
o_is_todo_fixme
o_is_work_item

14 changes: 7 additions & 7 deletions tests/testthat/_snaps/outline.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# file_outline() works

Code
file_outline(path = my_test_files, alpha = TRUE)
file_outline(my_test_files, alpha = TRUE)
Message
-- `my-analysis.md` My doc title
Expand Down Expand Up @@ -36,10 +36,10 @@
-- `title.md` The title is the only outline element

# alpha and work_only arguments work
# alpha arguments works

Code
file_outline("street", my_test_file, alpha = TRUE, work_only = FALSE)
file_outline(my_test_file, pattern = "street", alpha = TRUE)
Message
-- `outline/my-analysis.R` Analyse my {streets}
Expand All @@ -63,15 +63,15 @@
# pattern works as expected

Code
file_outline(pattern = "not found", path = file)
file_outline(file, pattern = "not found")
Message
`pattern = "not found"` did not return any results looking in 1 file.
i Run `` `proj_file()` `` to search in file names too.

---

Code
file_outline("Viz", path = file)
file_outline(file, "Viz")
Message
-- `outline-script.R` Example for `file_outline()`
Expand All @@ -81,15 +81,15 @@
---

Code
file_outline("Example for", path = file)
file_outline(file, "Example for")
Message
-- `outline-script.R` Example for `file_outline()`

# file_outline() detects correctly knitr notebooks

Code
file_outline(path = test_path("_outline", "knitr-notebook.R"))
file_outline(test_path("_outline", "knitr-notebook.R"))
Message
-- `knitr-notebook.R` Crop Analysis Q3 2013
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/test-outline-criteria.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ test_that("o_is_todo_fixme() works", {
expect_false(o_is_todo_fixme("#' TODO, WORK, FIXME)", is_roxygen_comment = T))
})

test_that("o_is_work_item() works", {
expect_true(o_is_work_item("# WORK this needs to be done."))
})

test_that("o_is_test_name() works", {
expect_true(o_is_test_name('test_that("Serious things are happening", {'))
expect_true(o_is_test_name('describe("This is happening", {'))
Expand Down
Loading

0 comments on commit 39385e5

Please sign in to comment.