Skip to content

Commit

Permalink
Incorporate more from #29 (including better version in NEWS.md
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Jun 3, 2024
1 parent c3801bc commit 6ab0c3f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ Be careful for markdown vs non-markdown (i.e. section title not the same)

5. If important, add to criteria in `define_important_element()`

6. Look at the result. Ideally, add to _ref/my-analysis.R, so it shows somehow in snapshots.
6. Look at the result. Ideally, add to _outline/my-analysis.R, so it shows somehow in snapshots.

NEWS.md is handled differently than other files.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

* `file_outline()` detects better plot titles and section titles.

* Package versions in NEWS.md are now normalized to yield better results.

# reuseme 0.0.2

* `complete_todo()` no longer deletes the full line. It only deletes what it says it deletes (#27).
Expand Down
22 changes: 11 additions & 11 deletions R/outline-criteria.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ o_is_todo_fixme <- function(x) {
# Eliminate candidates
has_todo[p] <-
!o_is_test_that(candidates) &
!stringr::str_starts(candidates, "\\s*\"\\s*") &
!grepl("extract_tag_in_text", candidates, fixed = TRUE) &
!o_is_roxygen_comment(candidates) & # don't put these tags in documentation :)
!stringr::str_detect(candidates, "grepl?\\(|g?sub\\(|str_detect|str_remove|str_extract|use_todo|,\\stodo\\)|TODO\\.R|TODO file|@param") &
!stringr::str_detect(candidates, "[:upper:]\"|[:upper:]{4,10} item") & # eliminate false positives
!stringr::str_detect(candidates, "\".{0,100}(TODO|FIXME|WORK)") # remove some true negs for now.
!stringr::str_starts(candidates, "\\s*\"\\s*") &
!grepl("extract_tag_in_text", candidates, fixed = TRUE) &
!o_is_roxygen_comment(candidates) & # don't put these tags in documentation :)
!stringr::str_detect(candidates, "grepl?\\(|g?sub\\(|str_detect|str_remove|str_extract|use_todo|,\\stodo\\)|TODO\\.R|TODO file|@param") &
!stringr::str_detect(candidates, "[:upper:]\"|[:upper:]{4,10} item") & # eliminate false positives
!stringr::str_detect(candidates, "\".{0,100}(TODO|FIXME|WORK)") # remove some true negs for now.
has_todo
}

Expand Down Expand Up @@ -131,11 +131,11 @@ o_is_cli_info <- function(x, is_snap_file = FALSE, file = "file") {

has_cli[p_cli] <-
stringr::str_detect(x[p_cli], "\\([\"']") &
!is_snap_file[p_cli] &
!grepl("outline.R", file[p_cli], fixed = TRUE) &
!stringr::str_detect(x[p_cli], "(text|inform|bullets|warn|abort|div)|\"cli|c\\(\\s?$") &
!grepl("paste", x[p_cli], fixed = TRUE) &
!grepl("^", x[p_cli], fixed = TRUE) # Detect UI messages and remove them
!is_snap_file[p_cli] &
!grepl("outline.R", file[p_cli], fixed = TRUE) &
!stringr::str_detect(x[p_cli], "(text|inform|bullets|warn|abort|div)|\"cli|c\\(\\s?$") &
!grepl("paste", x[p_cli], fixed = TRUE) &
!grepl("^", x[p_cli], fixed = TRUE) # Detect UI messages and remove them
has_cli
}

Expand Down
16 changes: 9 additions & 7 deletions R/outline.R
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,9 @@ keep_outline_element <- function(.data) {
if (any(.data$simplify_news)) {
# only keep dev, latest and major versions of NEWS.md in outline.
all_versions <- .data$pkg_version[!is.na(.data$pkg_version)]
keep <- all_versions == max(all_versions, na.rm = TRUE) |
endsWith(all_versions, ".0")
all_versions_norm <- package_version(all_versions)
keep <- all_versions_norm == max(all_versions_norm, na.rm = TRUE) |
endsWith(all_versions, "-0") | endsWith(all_versions, ".0")
versions_to_drop <- all_versions[!keep]
} else {
versions_to_drop <- character(0L)
Expand All @@ -487,12 +488,11 @@ keep_outline_element <- function(.data) {
# still regular comments in .md files
# what to keep in .md docs

(is_md & (is_chunk_cap | is_doc_title)) |
(is_md & (is_section_title & before_and_after_empty & !is_a_comment_or_code)) |
(is_md & (is_chunk_cap | (is_section_title & before_and_after_empty & !is_a_comment_or_code))) |
# What to keep in .R files
(!is_md & is_section_title_source) |
# What to keep anywhere
is_tab_or_plot_title | is_todo_fixme | is_test_name | is_cross_ref | is_function_def # | is_cli_info # TODO reanable cli info
is_tab_or_plot_title | is_todo_fixme | is_test_name | is_cross_ref | is_function_def | is_doc_title # | is_cli_info # TODO reanable cli info
)
dat$simplify_news <- NULL
dat
Expand All @@ -518,7 +518,8 @@ display_outline_element <- function(.data, dir_common) {
is_todo_fixme ~ stringr::str_extract(outline_el, "(TODO.+)|(FIXME.+)|(WORK.+)|(BOOK.+)"),
is_test_name ~ stringr::str_extract(outline_el, "test_that\\(['\"](.+)['\"],\\s?\\{", group = 1),
is_cli_info ~ stringr::str_extract(outline_el, "[\"'](.{5,})[\"']") |> stringr::str_remove_all("\""),
is_tab_or_plot_title ~ stringr::str_extract(outline_el, "title =[^\"']*[\"']([^\"]{5,})[\"']", group = 1), is_chunk_cap_next & !is_chunk_cap ~ stringr::str_remove_all(outline_el, "\\s?\\#\\|\\s+"),
is_tab_or_plot_title ~ stringr::str_extract(outline_el, "title =[^\"']*[\"']([^\"]{5,})[\"']", group = 1),
is_chunk_cap_next & !is_chunk_cap ~ stringr::str_remove_all(outline_el, "\\s?\\#\\|\\s+"),
is_chunk_cap ~ stringr::str_remove_all(stringr::str_extract(outline_el, "(cap|title)\\:\\s*(.+)", group = 2), "\"|'"),
is_cross_ref ~ stringr::str_remove_all(outline_el, "^(i.stat\\:\\:)?.cdocs_lin.s\\(|[\"']\\)$|\""),
is_doc_title ~ stringr::str_remove_all(outline_el, "subtitle\\:\\s?|title\\:\\s?|\"|\\#\\|\\s?"),
Expand Down Expand Up @@ -698,7 +699,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
is_saved_doc = NULL,
is_roxygen_comment = NULL,
is_news = NULL,
# I may put it pack
# I may put it back ...
importance = NULL,
# may be useful for debugging
before_and_after_empty = NULL,
Expand All @@ -707,6 +708,7 @@ construct_outline_link <- function(.data, is_saved_doc, dir_common, pattern) {
) |>
dplyr::filter(is.na(outline_el) | grepl(pattern, outline_el, ignore.case = TRUE))
}

trim_outline <- function(x, width) {
# problematic in case_when
cli::ansi_strtrim(x, width = width)
Expand Down

0 comments on commit 6ab0c3f

Please sign in to comment.