diff --git a/DESCRIPTION b/DESCRIPTION index 83feabd4b..09cad33f5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,7 +53,7 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate", if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else { warning("Please install r-lib/pkgapi to make sure the file API is kept up to date"); NULL})) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.2 Config/testthat/edition: 3 Config/testthat/parallel: true Collate: @@ -85,7 +85,7 @@ Collate: 'serialize.R' 'set-assert-args.R' 'style-guides.R' - 'styler.R' + 'styler-package.R' 'stylerignore.R' 'testing-mocks.R' 'testing-public-api.R' diff --git a/NAMESPACE b/NAMESPACE index 42f8c5ba2..53a3efbc9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,9 +32,6 @@ export(tidyverse_math_token_spacing) export(tidyverse_reindention) export(tidyverse_style) importFrom(magrittr,"%>%") -importFrom(magrittr,or) -importFrom(magrittr,set_names) -importFrom(purrr,as_mapper) importFrom(purrr,compact) importFrom(purrr,flatten) importFrom(purrr,flatten_chr) @@ -52,11 +49,7 @@ importFrom(purrr,pwalk) importFrom(purrr,when) importFrom(rlang,"%||%") importFrom(rlang,abort) -importFrom(rlang,is_empty) importFrom(rlang,is_installed) importFrom(rlang,seq2) +importFrom(rlang,set_names) importFrom(rlang,warn) -importFrom(rlang,with_handlers) -importFrom(utils,capture.output) -importFrom(utils,tail) -importFrom(utils,write.table) diff --git a/R/addins.R b/R/addins.R index ef5801a2d..8cfb7981b 100644 --- a/R/addins.R +++ b/R/addins.R @@ -45,7 +45,7 @@ NULL -#' @importFrom rlang abort + #' @keywords internal style_active_file <- function() { communicate_addins_style_transformers() @@ -118,7 +118,6 @@ save_after_styling_is_active <- function() { } #' Styles the highlighted selection in a `.R` or `.Rmd` file. -#' @importFrom rlang abort #' @keywords internal style_selection <- function() { communicate_addins_style_transformers() @@ -148,9 +147,7 @@ get_rstudio_context <- function() { } #' Asks the user to supply a style -#' @importFrom rlang abort #' @keywords internal -#' @importFrom rlang with_handlers abort set_style_transformers <- function() { current_style <- get_addins_style_transformer_name() new_style <- @@ -160,7 +157,7 @@ set_style_transformers <- function() { current_style ) if (!is.null(new_style)) { - parsed_new_style <- with_handlers( + parsed_new_style <- rlang::with_handlers( { transformers <- eval(parse(text = new_style)) style_text( @@ -182,7 +179,6 @@ set_style_transformers <- function() { } #' Return the style function or name -#' #' @keywords internal get_addins_style_transformer_name <- function() { getOption("styler.addins_style_transformer") @@ -210,10 +206,9 @@ communicate_addins_style_transformers <- function() { #' @param context The context from `styler:::get_rstudio_context()`. #' @param transformer A transformer function most conveniently constructed with #' [make_transformer()]. -#' @importFrom rlang with_handlers abort #' @keywords internal try_transform_as_r_file <- function(context, transformer) { - with_handlers( + rlang::with_handlers( transformer(context$contents), error = function(e) { preamble_for_unsaved <- paste( diff --git a/R/communicate.R b/R/communicate.R index 7c6961b35..e0a2b314b 100644 --- a/R/communicate.R +++ b/R/communicate.R @@ -40,8 +40,7 @@ communicate_summary <- function(changed, ruler_width) { } } -#' @importFrom rlang abort -#' @importFrom rlang is_installed + assert_data.tree_installation <- function() { if (!is_installed("data.tree")) { abort("The package data.tree needs to be installed for this functionality.") diff --git a/R/compat-dplyr.R b/R/compat-dplyr.R index ab5b15abe..df336de69 100644 --- a/R/compat-dplyr.R +++ b/R/compat-dplyr.R @@ -10,7 +10,7 @@ lead <- function(x, n = 1L, default = NA) { c(x[-seq_len(n)], rep(default, n)) } -#' @importFrom rlang abort + arrange <- function(.data, ...) { ord <- eval(substitute(order(...)), .data, parent.frame()) .data[ord, , drop = FALSE] @@ -81,9 +81,8 @@ slice <- function(.data, ...) { } # TODO: Use `purrr::map_dfr()` when it stops implicitly relying on `{dplyr}` -#' @importFrom purrr as_mapper map map_dfr <- function(.x, .f, ..., .id = NULL) { - .f <- as_mapper(.f, ...) + .f <- purrr::as_mapper(.f, ...) res <- map(.x, .f, ...) bind_rows(res, .id = .id) } diff --git a/R/detect-alignment-utils.R b/R/detect-alignment-utils.R index 8115ffda2..aecc1d49d 100644 --- a/R/detect-alignment-utils.R +++ b/R/detect-alignment-utils.R @@ -3,7 +3,6 @@ #' Must be after dropping comments because the closing brace is only guaranteed #' to be the last token in that case. #' @inheritParams alignment_drop_comments -#' @importFrom rlang seq2 #' @keywords internal alignment_ensure_no_closing_brace <- function(pd_by_line, last_line_droped_early) { @@ -28,7 +27,6 @@ alignment_ensure_no_closing_brace <- function(pd_by_line, #' @param pd_by_line A list, each element corresponding to a potentially #' incomplete parse table that represents all token from one line. #' @keywords internal -#' @importFrom purrr map compact alignment_drop_comments <- function(pd_by_line) { map(pd_by_line, function(x) { out <- x[x$token != "COMMENT", ] @@ -107,7 +105,6 @@ alignment_ensure_trailing_comma <- function(pd_by_line) { #' Checks if all arguments of column 1 are named #' @param relevant_pd_by_line A list with parse tables of a multi-line call, #' excluding first and last column. -#' @importFrom purrr map_lgl #' @keywords internal alignment_col1_all_named <- function(relevant_pd_by_line) { map_lgl(relevant_pd_by_line, function(x) { @@ -124,7 +121,6 @@ alignment_col1_all_named <- function(relevant_pd_by_line) { #' Serialize all lines for a given column #' @param column The index of the column to serialize. #' @inheritParams alignment_col1_all_named -#' @importFrom purrr map #' @keywords internal alignment_serialize_column <- function(relevant_pd_by_line, column) { map(relevant_pd_by_line, alignment_serialize_line, column = column) @@ -132,7 +128,6 @@ alignment_serialize_column <- function(relevant_pd_by_line, column) { #' Serialize one line for a column #' -#' #' @inheritParams alignment_serialize_column #' @inheritParams alignment_col1_all_named #' @keywords internal @@ -147,7 +142,7 @@ alignment_serialize_line <- function(relevant_pd_by_line, column) { # line does not have values at that column return(NULL) } - between_commas <- seq2(max(1, comma_idx[column - 1L]), comma_idx[column]) + between_commas <- seq2(max(1L, comma_idx[column - 1L]), comma_idx[column]) relevant_pd_by_line <- relevant_pd_by_line[between_commas, ] alignment_serialize(relevant_pd_by_line) } @@ -178,7 +173,7 @@ alignment_serialize <- function(pd_sub) { #' At least one space after comma, none before, for all but the last comma on #' the line #' @param pd_sub The subset of a parse table corresponding to one line. -#' @importFrom rlang seq2 +#' #' @keywords internal alignment_has_correct_spacing_around_comma <- function(pd_sub) { comma_tokens <- which(pd_sub$token == "','") @@ -196,14 +191,13 @@ alignment_has_correct_spacing_around_comma <- function(pd_sub) { #' At least one space around `EQ_SUB` #' @inheritParams alignment_has_correct_spacing_around_comma #' @keywords internal -#' @importFrom rlang seq2 alignment_has_correct_spacing_around_eq_sub <- function(pd_sub) { relevant_eq_sub_token <- which(pd_sub$token == "EQ_SUB") if (length(relevant_eq_sub_token) == 0L) { return(TRUE) } - correct_spaces_before <- pd_sub$.lag_spaces[relevant_eq_sub_token] >= 1 - correct_spaces_after <- pd_sub$spaces[relevant_eq_sub_token] >= 1 + correct_spaces_before <- pd_sub$.lag_spaces[relevant_eq_sub_token] >= 1L + correct_spaces_after <- pd_sub$spaces[relevant_eq_sub_token] >= 1L all(correct_spaces_before) && all(correct_spaces_after) } diff --git a/R/detect-alignment.R b/R/detect-alignment.R index 780ae1da1..b08ddfeb3 100644 --- a/R/detect-alignment.R +++ b/R/detect-alignment.R @@ -22,8 +22,6 @@ #' * For the recursive creation of text, greedily check column by column to make #' sure we can stop as soon as we found that columns are not aligned. #' -#' @importFrom purrr map_int map_lgl map compact -#' @importFrom rlang seq2 #' @keywords internal #' @examples #' library("magrittr") diff --git a/R/indent.R b/R/indent.R index bcf7a0c73..8ff7d26b7 100644 --- a/R/indent.R +++ b/R/indent.R @@ -29,7 +29,7 @@ indent_without_paren_for_while_fun <- function(pd, indent_by) { } #' @describeIn update_indention Is used to indent if and if-else statements. -#' @importFrom rlang seq2 +#' #' @keywords internal indent_without_paren_if_else <- function(pd, indent_by) { expr_after_if <- next_non_comment(pd, which(pd$token == "')'")[1L]) @@ -91,7 +91,7 @@ indent_without_paren_if_else <- function(pd, indent_by) { #' Since text `[[` has token `"LBB"` and text `]]` is parsed as two independent #' `]` (see 'Examples'), indention has to stop at the first `]`. # one token earlier -#' @importFrom rlang seq2 +#' #' @keywords internal #' @examples #' styler:::parse_text("a[1]") @@ -161,7 +161,7 @@ needs_indention <- function(pd, #' if on the same line as the token corresponding to `potential_trigger` and #' directly followed by a line break. #' @return `TRUE` if indention is needed, `FALSE` otherwise. -#' @importFrom rlang seq2 +#' #' @keywords internal #' @examples #' style_text(c( @@ -206,7 +206,6 @@ needs_indention_one <- function(pd, #' Sets the column `multi_line` in `pd` by checking row-wise whether any child #' of a token is a multi-line token. #' @param pd A parse table. -#' @importFrom purrr map_lgl #' @keywords internal set_multi_line <- function(pd) { pd$multi_line <- unname(map_int(pd$child, pd_multi_line)) diff --git a/R/initialize.R b/R/initialize.R index c130ded0b..87b0a1e62 100644 --- a/R/initialize.R +++ b/R/initialize.R @@ -3,7 +3,6 @@ #' This function initializes and removes various variables from the parse #' table. #' @param pd_flat A parse table. -#' @importFrom utils tail #' @examples #' withr::with_options( #' list(styler.cache_name = NULL), # temporarily deactivate cache @@ -37,7 +36,7 @@ NULL #' @describeIn initialize_attributes Initializes `newlines` and `lag_newlines`. #' @keywords internal initialize_newlines <- function(pd_flat) { - pd_flat$line3 <- lead(pd_flat$line1, default = tail(pd_flat$line2, 1L)) + pd_flat$line3 <- lead(pd_flat$line1, default = utils::tail(pd_flat$line2, 1L)) pd_flat$newlines <- pd_flat$line3 - pd_flat$line2 pd_flat$lag_newlines <- lag(pd_flat$newlines, default = 0L) pd_flat$line3 <- NULL @@ -47,7 +46,7 @@ initialize_newlines <- function(pd_flat) { #' @describeIn initialize_attributes Initializes `spaces`. #' @keywords internal initialize_spaces <- function(pd_flat) { - pd_flat$col3 <- lead(pd_flat$col1, default = tail(pd_flat$col2, 1L) + 1L) + pd_flat$col3 <- lead(pd_flat$col1, default = utils::tail(pd_flat$col2, 1L) + 1L) pd_flat$col2_nl <- ifelse(pd_flat$newlines > 0L, rep(0L, nrow(pd_flat)), pd_flat$col2 ) @@ -88,7 +87,7 @@ initialize_indent <- function(pd_flat) { pd_flat } -#' @importFrom rlang abort + #' @describeIn initialize_attributes validates the parse data. #' @keywords internal validate_parse_data <- function(pd_flat) { diff --git a/R/io.R b/R/io.R index e79364979..2bc615d17 100644 --- a/R/io.R +++ b/R/io.R @@ -1,8 +1,6 @@ #' Apply a function to the contents of a file #' #' Transforms a file with a function. -#' @importFrom magrittr set_names -#' @importFrom rlang abort #' @inheritParams transform_utf8_one #' @keywords internal transform_utf8 <- function(path, fun, dry) { @@ -19,11 +17,10 @@ transform_utf8 <- function(path, fun, dry) { #' latter returns an error if the input code is not identical to the result #' of styling. "off", the default, writes back if the input and output of #' styling are not identical. -#' @importFrom rlang with_handlers warn #' @keywords internal transform_utf8_one <- function(path, fun, dry) { rlang::arg_match(dry, c("on", "off", "fail")) - with_handlers( + rlang::with_handlers( { file_with_info <- read_utf8(path) # only write back when changed OR when there was a missing newline diff --git a/R/nest.R b/R/nest.R index 32b035956..aab93d9f9 100644 --- a/R/nest.R +++ b/R/nest.R @@ -5,7 +5,6 @@ #' @inheritParams text_to_flat_pd #' @return A nested parse table. See [tokenize()] for details on the columns #' of the parse table. -#' @importFrom purrr when #' @examples #' code <- " #' ab <- 1L # some comment @@ -60,7 +59,6 @@ text_to_flat_pd <- function(text, transformers, more_specs) { #' input. #' @param pd_nested A top level nest. #' @keywords internal -#' @importFrom rlang seq2 add_cache_block <- function(pd_nested) { if (cache_is_activated()) { pd_nested$block <- cache_find_block(pd_nested) @@ -342,7 +340,6 @@ set_spaces <- function(spaces_after_prefix, force_one) { #' @param pd_flat A flat parse table including both terminals and non-terminals. #' @seealso [compute_parse_data_nested()] #' @return A nested parse table. -#' @importFrom purrr map2 #' @keywords internal nest_parse_data <- function(pd_flat) { if (all(pd_flat$parent <= 0L)) { diff --git a/R/nested-to-tree.R b/R/nested-to-tree.R index f0bde0e8c..f2523f65a 100644 --- a/R/nested-to-tree.R +++ b/R/nested-to-tree.R @@ -4,7 +4,6 @@ #' @param text A character vector. #' @inheritParams create_node_from_nested_root #' @return A data frame. -#' @importFrom purrr when #' @keywords internal create_tree <- function(text, structure_only = FALSE) { compute_parse_data_nested(text, transformers = NULL) %>% @@ -62,7 +61,6 @@ create_node_from_nested_root <- function(pd_nested, structure_only) { #' #' @inheritParams create_node_from_nested_root #' @param parent The parent of the node to be created. -#' @importFrom purrr map2 map #' @keywords internal create_node_from_nested <- function(pd_nested, parent, structure_only) { if (is.null(pd_nested)) { diff --git a/R/parse.R b/R/parse.R index 06bf64502..cf3814909 100644 --- a/R/parse.R +++ b/R/parse.R @@ -5,8 +5,7 @@ #' that we can only detect wrong EOL style if it occurs on the first line #' already. #' @param text Text to parse. -#' @param ... Parameters passed to [base::parse()] -#' @importFrom rlang abort with_handlers warn +#' @param ... Parameters passed to [base::parse()]. #' @keywords internal #' @examples #' \dontrun{ @@ -17,7 +16,7 @@ #' } #' styler:::parse_safely("a + 3 -4 -> \n glück + 1") parse_safely <- function(text, ...) { - tried_parsing <- with_handlers( + tried_parsing <- rlang::with_handlers( parse(text = text, ...), error = function(e) e, warning = function(w) w @@ -72,7 +71,7 @@ has_crlf_as_first_line_sep <- function(message, initial_text) { #' #' @inheritParams get_parse_data #' @return A flat parse table -#' @importFrom rlang seq2 +#' #' @keywords internal tokenize <- function(text) { get_parse_data(text, include_text = TRUE) %>% @@ -132,11 +131,9 @@ add_id_and_short <- function(pd) { #' with the text of their parents if their line / col position matches and #' return an error otherwise. #' @param pd A parse table. -#' @importFrom rlang abort -#' @importFrom magrittr or #' @keywords internal ensure_correct_txt <- function(pd, text) { - is_problematic_text <- or( + is_problematic_text <- magrittr::or( is_insufficiently_parsed_string(pd), is_insufficiently_parsed_number(pd) ) @@ -146,7 +143,7 @@ ensure_correct_txt <- function(pd, text) { problematic_text <- pd[is_problematic_text, ] is_parent_of_problematic_string <- pd$id %in% problematic_text$parent - is_unaffected_token <- !or( + is_unaffected_token <- !magrittr::or( is_problematic_text, is_parent_of_problematic_string ) diff --git a/R/reindent.R b/R/reindent.R index 28a2735e4..d479ba07c 100644 --- a/R/reindent.R +++ b/R/reindent.R @@ -84,7 +84,6 @@ find_tokens_to_update <- function(flattened_pd, target_token) { #' checked or all tokens. #' @return A flattened parse table with indention set to `target_indention` for #' the tokens that match `regex.` -#' @importFrom purrr map flatten_int #' @keywords internal set_regex_indention <- function(flattened_pd, pattern, diff --git a/R/relevel.R b/R/relevel.R index eb376d82b..70b8b6a65 100644 --- a/R/relevel.R +++ b/R/relevel.R @@ -172,7 +172,7 @@ relocate_eq_assign <- function(pd) { #' #' Please refer to the section 'Examples' in [relocate_eq_assign()] for details. #' @param pd A parse table. -#' @importFrom rlang seq2 +#' #' @keywords internal relocate_eq_assign_nest <- function(pd) { idx_eq_assign <- which(pd$token == "EQ_ASSIGN") @@ -236,7 +236,7 @@ relocate_eq_assign_one <- function(pd) { #' Adds line and col information to an expression from its child #' #' @param pd A parse table. -#' @importFrom rlang abort + #' @keywords internal add_line_col_to_wrapped_expr <- function(pd) { if (nrow(pd) > 1) abort("pd must be a wrapped expression that has one row.") diff --git a/R/roxygen-examples-add-remove.R b/R/roxygen-examples-add-remove.R index 60c37dbbf..a29e14b3c 100644 --- a/R/roxygen-examples-add-remove.R +++ b/R/roxygen-examples-add-remove.R @@ -2,7 +2,7 @@ #' #' @param roxygen Roxygen code examples that contains a dont* segment only. #' @keywords internal -#' @importFrom rlang seq2 +#' remove_dont_mask <- function(roxygen) { mask <- c( 1L, 2L, if (roxygen[3L] == "\n") 3L, last(which(roxygen == "}")) @@ -41,7 +41,6 @@ remove_roxygen_header <- function(text) { #' potentially ordinary comments. #' @param example_type Either 'examples' or 'examplesIf'. #' @keywords internal -#' @importFrom purrr map2_chr add_roxygen_mask <- function(text, initial_text, example_type) { space <- ifelse(text == "", "", " ") out <- c( diff --git a/R/roxygen-examples-find.R b/R/roxygen-examples-find.R index 2448e302d..5cc4036dd 100644 --- a/R/roxygen-examples-find.R +++ b/R/roxygen-examples-find.R @@ -3,15 +3,13 @@ #' Finds the sequence from start to stop of the lines in `text` that are #' code examples in roxygen comments. #' @param text A text consisting of code and/or roxygen comments. -#' @importFrom purrr map_int map2 -#' @importFrom rlang seq2 #' @keywords internal identify_start_to_stop_of_roxygen_examples_from_text <- function(text) { starts <- grep("^#'(\\s|\t)*@examples(If\\s|\\s|\t|$)", text, perl = TRUE) if (length(starts) < 1L) { return(integer()) } - stop_candidates <- which(or( + stop_candidates <- which(magrittr::or( grepl("(^[^#]|^#'[\\s\t]*@)", text, perl = TRUE), grepl("^ *\t*$", text) & grepl("^#' *", lead(text)) )) @@ -44,12 +42,11 @@ match_stop_to_start <- function(start, stop_candidates) { } } -#' Find dontrun and friend sequences +#' Find `dontrun` and friend sequences #' #' Returns the indices of the lines that correspond to a `dontrun` or #' friends sequence. #' @param bare Bare code. -#' @importFrom purrr map2 map_int #' @keywords internal find_dont_seqs <- function(bare) { dont_openings <- which(bare %in% dont_keywords()) @@ -57,7 +54,7 @@ find_dont_seqs <- function(bare) { map2(dont_openings, dont_closings, seq2) } -#' @importFrom rlang seq2 +#' find_dont_closings <- function(bare, dont_openings) { opening <- cumsum(bare == "{") closing <- cumsum(bare == "}") diff --git a/R/roxygen-examples.R b/R/roxygen-examples.R index 8bee1c41d..e8d4c9b6e 100644 --- a/R/roxygen-examples.R +++ b/R/roxygen-examples.R @@ -6,7 +6,6 @@ #' @inheritParams parse_transform_serialize_r #' @param example Roxygen example code. #' @inheritSection parse_transform_serialize_roxygen Hierarchy -#' @importFrom purrr map flatten_chr #' @keywords internal style_roxygen_code_example <- function(example, transformers, base_indention) { example <- split(example, cumsum(grepl("^#' *@examples", example))) @@ -33,7 +32,7 @@ style_roxygen_code_example_one <- function(example_one, ) %>% flatten_chr() if (bare$example_type == "examplesIf") { - with_handlers( + rlang::with_handlers( parse_text(unmasked[1L]), error = function(e) { abort(paste0( @@ -64,8 +63,6 @@ style_roxygen_code_example_one <- function(example_one, #' friends. #' @inheritParams parse_transform_serialize_r #' @inheritSection parse_transform_serialize_roxygen Hierarchy -#' @importFrom rlang seq2 -#' @importFrom purrr map2 flatten_chr #' @keywords internal style_roxygen_code_example_segment <- function(one_dont, transformers, diff --git a/R/rules-indention.R b/R/rules-indention.R index f21583bcd..68e62862b 100644 --- a/R/rules-indention.R +++ b/R/rules-indention.R @@ -102,7 +102,7 @@ NULL #' x + y #' } #' } -#' @importFrom rlang seq2 +#' #' @keywords internal update_indention_ref_fun_dec <- function(pd_nested) { if (pd_nested$token[1L] == "FUNCTION") { diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 2d2a68bb2..fec8c359e 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -240,7 +240,7 @@ remove_line_breaks_in_fun_dec <- function(pd) { pd } -#' @importFrom rlang seq2 +#' add_line_break_after_pipe <- function(pd) { is_pipe <- pd$token %in% c("SPECIAL-PIPE", "PIPE") pd$lag_newlines[lag(is_pipe) & pd$lag_newlines > 1L] <- 1L @@ -272,7 +272,7 @@ set_line_break_after_assignment <- function(pd) { #' @param force_text_before A character vector with text before "'('" that #' forces a line break after every argument in the call. #' @name set_line_break_if_call_is_multi_line -#' @importFrom rlang seq2 +#' #' @keywords internal NULL diff --git a/R/rules-spaces.R b/R/rules-spaces.R index 271a00a59..f9dbb293f 100644 --- a/R/rules-spaces.R +++ b/R/rules-spaces.R @@ -251,7 +251,6 @@ set_space_between_levels <- function(pd_flat) { #' #' @param pd A parse table. #' @param force_one Whether or not to force one space or allow multiple spaces. -#' @importFrom purrr map_chr #' @keywords internal start_comments_with_space <- function(pd, force_one = FALSE) { is_comment <- is_comment(pd) diff --git a/R/rules-tokens.R b/R/rules-tokens.R index 8f77897f0..3be21f1d6 100644 --- a/R/rules-tokens.R +++ b/R/rules-tokens.R @@ -67,7 +67,6 @@ add_brackets_in_pipe_one <- function(pd, pos) { #' @param indent_by The amount of spaces used to indent an expression in curly #' braces. Used for unindention. #' @keywords internal -#' @importFrom purrr when wrap_if_else_while_for_fun_multi_line_in_curly <- function(pd, indent_by = 2L) { key_token <- when( pd, @@ -196,13 +195,11 @@ if_for_while_part_requires_braces <- function(pd, key_token) { #' style_text("'here #' is a string #' '") -#' @importFrom purrr map map_chr #' @param pd_flat A flat parse table. -#' @importFrom rlang is_empty #' @keywords internal fix_quotes <- function(pd_flat) { str_const <- which(pd_flat$token == "STR_CONST") - if (is_empty(str_const)) { + if (rlang::is_empty(str_const)) { return(pd_flat) } @@ -210,11 +207,10 @@ fix_quotes <- function(pd_flat) { pd_flat } -#' @importFrom rlang is_empty fix_quotes_one <- function(x) { rx <- "^'([^\"]*)'$" i <- grep(rx, x) - if (is_empty(i)) { + if (rlang::is_empty(i)) { return(x) } diff --git a/R/set-assert-args.R b/R/set-assert-args.R index e9c4a5a3f..1787ba246 100644 --- a/R/set-assert-args.R +++ b/R/set-assert-args.R @@ -69,7 +69,7 @@ set_and_assert_arg_filetype <- function(filetype) { #' Make sure all supplied file types are allowed #' #' @param lowercase_filetype A vector with file types to check, all lower case. -#' @importFrom rlang abort + #' @keywords internal assert_filetype <- function(lowercase_filetype) { allowed_types <- c("r", "rmd", "rmarkdown", "rnw", "rprofile", "qmd") @@ -96,7 +96,7 @@ assert_text <- function(text) { #' #' Check whether one or more tokens exist and have a unique token-text mapping #' @param tokens Tokens to check. -#' @importFrom rlang abort + #' @keywords internal assert_tokens <- function(tokens) { invalid_tokens <- tokens[!(tokens %in% lookup_tokens()$token)] diff --git a/R/style-guides.R b/R/style-guides.R index 969bc4caa..444fe5318 100644 --- a/R/style-guides.R +++ b/R/style-guides.R @@ -61,7 +61,6 @@ NULL #' #' # styling line breaks only without spaces #' style_text(c("ab <- 3", "a =3"), strict = TRUE, scope = I(c("line_breaks", "tokens"))) -#' @importFrom purrr partial #' @export tidyverse_style <- function(scope = "tokens", strict = TRUE, @@ -324,7 +323,6 @@ tidyverse_style <- function(scope = "tokens", #' "a <- function(x) { x }", #' style = set_line_break_before_curly_opening_style #' ) -#' @importFrom purrr compact #' @export create_style_guide <- function(initialize = default_style_guide_attributes, line_break = NULL, @@ -477,7 +475,7 @@ tidyverse_reindention <- function() { #' @param scope A character vector of length one or a vector of class `AsIs`. #' @param name The name of the character vector to be displayed if the #' construction of the factor fails. -#' @importFrom rlang abort + #' @examples #' scope_normalize(I("tokens")) #' scope_normalize(I(c("indention", "tokens"))) diff --git a/R/styler.R b/R/styler-package.R similarity index 58% rename from R/styler.R rename to R/styler-package.R index a6e44e870..c3c3d4b7c 100644 --- a/R/styler.R +++ b/R/styler-package.R @@ -18,15 +18,24 @@ #' style_text("a%>%b; a", scope = "tokens") "_PACKAGE" -if (getRversion() >= "2.15.1") { - utils::globalVariables(c( - ".", - "pd", "pd_nested", "pd_flat", "flattened_pd", - "line1", "line2", "col1", "col2", "parent", - "terminal", "text", "short", - "spaces", "lag_spaces", - "newlines", "lag_newlines", - "pos_id", - NULL - )) -} +## styler namespace: start +#' +#' @importFrom rlang abort warn seq2 is_installed "%||%" set_names +#' @importFrom purrr map map_lgl map_int map_chr map2 map2_chr map_at pmap pwalk +#' @importFrom purrr compact when partial flatten flatten_int flatten_chr +#' @importFrom magrittr "%>%" +#' +## styler namespace: end +NULL + + +utils::globalVariables(c( + ".", + "pd", "pd_nested", "pd_flat", "flattened_pd", + "line1", "line2", "col1", "col2", "parent", + "terminal", "text", "short", + "spaces", "lag_spaces", + "newlines", "lag_newlines", + "pos_id", + NULL +)) diff --git a/R/stylerignore.R b/R/stylerignore.R index 8dc04de0e..80456562d 100644 --- a/R/stylerignore.R +++ b/R/stylerignore.R @@ -11,7 +11,6 @@ #' start marker can have many tokens). #' @inheritParams add_stylerignore #' @keywords internal -#' @importFrom purrr map env_add_stylerignore <- function(pd_flat) { if (!env_current$any_stylerignore) { env_current$stylerignore <- pd_flat[0, ] diff --git a/R/testing-public-api.R b/R/testing-public-api.R index 16f0e73b3..6464cec1b 100644 --- a/R/testing-public-api.R +++ b/R/testing-public-api.R @@ -15,14 +15,13 @@ #' This also implies that the ruler width, which depend on the path #' length, will again have the same width on all systems and is independent of #' how many characters the path of the temporary directory has. -#' @importFrom utils capture.output #' @keywords internal catch_style_file_output <- function(file_in) { file_in <- testthat_file(file_in) temp_path <- copy_to_tempdir(file_in) raw_output <- withr::with_dir( dirname(temp_path), - capture.output( + utils::capture.output( style_file(basename(temp_path), scope = "tokens") ) ) diff --git a/R/testing.R b/R/testing.R index c0f839609..96aca3ae8 100644 --- a/R/testing.R +++ b/R/testing.R @@ -16,8 +16,6 @@ #' last dash and adding -out.R. In contrast to older versions of this #' function, every *-out.R file has just one in file. #' @inheritParams transform_and_check -#' @importFrom purrr flatten_chr pwalk map -#' @importFrom rlang abort #' @keywords internal test_collection <- function(test, sub_test = NULL, dry = "off", @@ -101,8 +99,6 @@ construct_tree <- function(in_paths, suffix = "_tree") { #' @param ... Parameters passed to transformer function. #' @param out_tree Name of tree file if written out. #' @inheritParams transform_utf8 -#' @importFrom utils write.table -#' @importFrom rlang warn #' @keywords internal transform_and_check <- function(in_item, out_item, in_name = in_item, out_name = out_item, @@ -113,7 +109,7 @@ transform_and_check <- function(in_item, out_item, read_in <- read_utf8_bare(in_item) if (write_tree) { create_tree(read_in) %>% - write.table(out_tree, + utils::write.table(out_tree, col.names = FALSE, row.names = FALSE, quote = FALSE, fileEncoding = "UTF-8" ) diff --git a/R/token-create.R b/R/token-create.R index 062f57053..279d54e97 100644 --- a/R/token-create.R +++ b/R/token-create.R @@ -144,7 +144,7 @@ find_start_pos_id <- function(pd, #' @param new_ids A vector with new ids #' @param after Whether the ids are created with `after = TRUE` (and hence #' should be in the range x.0-x.45) or not. -#' @importFrom rlang abort + #' @family token creators #' @keywords internal validate_new_pos_ids <- function(new_ids, after) { diff --git a/R/token-define.R b/R/token-define.R index 6a44d95af..0954bcb80 100644 --- a/R/token-define.R +++ b/R/token-define.R @@ -43,7 +43,6 @@ lookup_tokens <- function() { #' Lookup which new tokens were created from "SPECIAL" #' #' @param regex A regular expression pattern to search for. -#' @importFrom purrr map_chr #' @keywords internal lookup_new_special <- function(regex = NA) { new_special <- c("PIPE", "IN", "OTHER") diff --git a/R/transform-code.R b/R/transform-code.R index 5224e9ac4..d8ecebc36 100644 --- a/R/transform-code.R +++ b/R/transform-code.R @@ -6,7 +6,7 @@ #' #' @inheritParams transform_utf8 #' @param ... Further arguments passed to [transform_utf8()]. -#' @importFrom rlang abort + #' @keywords internal transform_code <- function(path, fun, ..., dry) { if (is_plain_r_file(path) || is_rprofile_file(path)) { @@ -34,7 +34,6 @@ transform_code <- function(path, fun, ..., dry) { #' #' @param transformer_fun A styler transformer function. #' @inheritParams separate_chunks -#' @importFrom purrr flatten_chr #' @keywords internal transform_mixed <- function(lines, transformer_fun, filetype) { chunks <- separate_chunks(lines, filetype) @@ -63,8 +62,6 @@ transform_mixed_non_empty <- function(r_chunk, transformer_fun) { #' code) within an Rmd or Rnw file, and returns these separately. #' @param lines A character vector of lines from an Rmd or Rnw file. #' @param filetype A string indicating the filetype - either 'Rmd' or 'Rnw'. -#' @importFrom purrr map2 -#' @importFrom rlang seq2 #' @keywords internal separate_chunks <- function(lines, filetype) { r_raw_chunks <- identify_raw_chunks(lines, filetype = filetype) @@ -91,7 +88,7 @@ separate_chunks <- function(lines, filetype) { #' matched twice, on which we throw an error. #' @inheritParams separate_chunks #' @param engine_pattern A regular expression that must match the engine name. -#' @importFrom rlang abort + #' @keywords internal identify_raw_chunks <- function(lines, filetype, diff --git a/R/transform-files.R b/R/transform-files.R index 019cc2b47..11d833c0b 100644 --- a/R/transform-files.R +++ b/R/transform-files.R @@ -93,7 +93,6 @@ transform_file <- function(path, #' examples. #' @inheritParams parse_transform_serialize_r #' @keywords internal -#' @importFrom purrr when make_transformer <- function(transformers, include_roxygen_examples, base_indention, @@ -167,7 +166,6 @@ make_transformer <- function(transformers, #' Finally, that we have roxygen code snippets that are either dont* or not, #' we style them in [style_roxygen_example_snippet()] using #' [parse_transform_serialize_r()]. -#' @importFrom purrr map_at flatten_chr #' @keywords internal parse_transform_serialize_roxygen <- function(text, transformers, @@ -206,7 +204,7 @@ parse_transform_serialize_roxygen <- function(text, #' sections. This list is named `separated`. #' * An integer vector with the indices that correspond to roxygen code #' examples in `separated`. -#' @importFrom rlang seq2 +#' #' @keywords internal split_roxygen_segments <- function(text, roxygen_examples) { if (is.null(roxygen_examples)) { @@ -233,7 +231,7 @@ split_roxygen_segments <- function(text, roxygen_examples) { #' @inheritParams compute_parse_data_nested #' @inheritParams parse_transform_serialize_r_block #' @seealso [parse_transform_serialize_roxygen()] -#' @importFrom rlang abort + #' @keywords internal parse_transform_serialize_r <- function(text, transformers, @@ -340,7 +338,6 @@ transformers_drop <- function(text, transformers) { #' #' @param pd_nested A nested parse table. #' @param transformers A list of *named* transformer functions -#' @importFrom purrr flatten #' @keywords internal apply_transformers <- function(pd_nested, transformers) { transformed_updated_multi_line <- post_visit( @@ -393,7 +390,7 @@ parse_tree_must_be_identical <- function(transformers) { #' Note that this method ignores roxygen code examples and #' comments and no verification can be conducted if tokens are in the styling #' scope. -#' @importFrom rlang abort + #' @examples #' styler:::verify_roundtrip("a+1", "a + 1") #' styler:::verify_roundtrip("a+1", "a + 1 # comments are dropped") diff --git a/R/ui-caching.R b/R/ui-caching.R index 0fab7c216..1bfc14031 100644 --- a/R/ui-caching.R +++ b/R/ui-caching.R @@ -113,7 +113,6 @@ cache_info <- function(cache_name = NULL, format = "both") { #' @param verbose Whether or not to print an informative message about what the #' function is doing. #' -#' @importFrom rlang "%||%" #' @family cache managers #' @export cache_activate <- function(cache_name = NULL, diff --git a/R/ui-styling.R b/R/ui-styling.R index b208ff122..ccbd40f3c 100644 --- a/R/ui-styling.R +++ b/R/ui-styling.R @@ -1,7 +1,3 @@ -#' @keywords api -#' @importFrom magrittr %>% -NULL - #' Prettify R source code #' #' Performs various substitutions in all `.R` files in a package diff --git a/R/unindent.R b/R/unindent.R index bbc0c9f8c..7aeff5ccb 100644 --- a/R/unindent.R +++ b/R/unindent.R @@ -3,8 +3,6 @@ #' check whether any of the children of `pd` has `token` on the same line as the #' closing `token` of pd. If so, unindent that token. #' @inheritParams unindent_child -#' @importFrom purrr map -#' @importFrom rlang seq2 #' @keywords internal set_unindention_child <- function(pd, token = "')'", unindent_by) { if (all(pd$indent == 0L) || all(pd$terminal)) { diff --git a/R/utils-navigate-nest.R b/R/utils-navigate-nest.R index f518b8c69..d1a84ff63 100644 --- a/R/utils-navigate-nest.R +++ b/R/utils-navigate-nest.R @@ -1,7 +1,7 @@ #' Find the index of the next or previous non-comment in a parse table. #' @param pd A parse table. #' @param pos The position of the token to start the search from. -#' @importFrom rlang seq2 +#' #' @examples #' code <- "a <- # hi \n x %>% b()" #' writeLines(code) diff --git a/R/vertical.R b/R/vertical.R index 5f0427bf9..2dae20f56 100644 --- a/R/vertical.R +++ b/R/vertical.R @@ -16,7 +16,6 @@ construct_vertical <- function(x) { #' @param colored Whether or not the output should be colored with #' `prettycode::highlight()`. #' @param style Passed to `prettycode::highlight()`. -#' @importFrom rlang is_installed warn #' @export print.vertical <- function(x, ..., colored = getOption("styler.colored_print.vertical"), diff --git a/R/visit.R b/R/visit.R index 8c16382dd..7e6600ea3 100644 --- a/R/visit.R +++ b/R/visit.R @@ -9,7 +9,6 @@ #' @param pd_nested A nested parse table. #' @inheritParams visit_one #' @family visitors -#' @importFrom purrr map #' @name visit #' @keywords internal NULL @@ -120,7 +119,6 @@ visit_one <- function(pd_flat, funs) { #' relative in `pd_nested`) will be converted into absolute. #' @inherit context_towards_terminals #' @seealso context_towards_terminals visitors -#' @importFrom purrr pmap #' @keywords internal context_to_terminals <- function(pd_nested, outer_lag_newlines, diff --git a/man/find_dont_seqs.Rd b/man/find_dont_seqs.Rd index b2b9d8bcd..75a90e6c7 100644 --- a/man/find_dont_seqs.Rd +++ b/man/find_dont_seqs.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/roxygen-examples-find.R \name{find_dont_seqs} \alias{find_dont_seqs} -\title{Find dontrun and friend sequences} +\title{Find \code{dontrun} and friend sequences} \usage{ find_dont_seqs(bare) } diff --git a/man/parse_safely.Rd b/man/parse_safely.Rd index 8e6ee62b0..68f1ae2b3 100644 --- a/man/parse_safely.Rd +++ b/man/parse_safely.Rd @@ -9,7 +9,7 @@ parse_safely(text, ...) \arguments{ \item{text}{Text to parse.} -\item{...}{Parameters passed to \code{\link[base:parse]{base::parse()}}} +\item{...}{Parameters passed to \code{\link[base:parse]{base::parse()}}.} } \description{ Parses text safely, i.e. throws an informative error if EOL style does not diff --git a/man/styler-package.Rd b/man/styler-package.Rd index 7c719da9b..0995015ad 100644 --- a/man/styler-package.Rd +++ b/man/styler-package.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/styler.R +% Please edit documentation in R/styler-package.R \docType{package} \name{styler-package} \alias{styler} diff --git a/man/update_indention_ref.Rd b/man/update_indention_ref.Rd index 8eb7712b1..a041faead 100644 --- a/man/update_indention_ref.Rd +++ b/man/update_indention_ref.Rd @@ -29,5 +29,6 @@ a <- function(x, x + y } } + } \keyword{internal} diff --git a/tests/testthat/indention_square_brackets/square_brackets_double_line_break-in_tree b/tests/testthat/indention_square_brackets/square_brackets_double_line_break-in_tree new file mode 100644 index 000000000..f6ae4068d --- /dev/null +++ b/tests/testthat/indention_square_brackets/square_brackets_double_line_break-in_tree @@ -0,0 +1,46 @@ +ROOT (token: short_text [lag_newlines/spaces] {pos_id}) + ¦--expr: a[[b] [0/0] {1} + ¦ ¦--expr: a [0/0] {3} + ¦ ¦ °--SYMBOL: a [0/0] {2} + ¦ ¦--LBB: [[ [0/0] {4} + ¦ ¦--expr: b [0/0] {6} + ¦ ¦ °--SYMBOL: b [0/0] {5} + ¦ ¦--']': ] [0/0] {7} + ¦ °--']': ] [0/0] {8} + ¦--expr: a[[ + [3/0] {9} + ¦ ¦--expr: a [0/0] {11} + ¦ ¦ °--SYMBOL: a [0/0] {10} + ¦ ¦--LBB: [[ [0/2] {12} + ¦ ¦--expr: 2 [1/0] {14} + ¦ ¦ °--NUM_CONST: 2 [0/0] {13} + ¦ ¦--']': ] [1/0] {15} + ¦ °--']': ] [1/0] {16} + ¦--expr: a[[ + [2/0] {17} + ¦ ¦--expr: a [0/0] {19} + ¦ ¦ °--SYMBOL: a [0/0] {18} + ¦ ¦--LBB: [[ [0/2] {20} + ¦ ¦--expr: 2 [1/0] {22} + ¦ ¦ °--NUM_CONST: 2 [0/0] {21} + ¦ ¦--']': ] [1/0] {23} + ¦ °--']': ] [0/0] {24} + ¦--expr: a[[ +2 [3/0] {25} + ¦ ¦--expr: a [0/0] {27} + ¦ ¦ °--SYMBOL: a [0/0] {26} + ¦ ¦--LBB: [[ [0/0] {28} + ¦ ¦--expr: 2 [1/2] {30} + ¦ ¦ °--NUM_CONST: 2 [0/0] {29} + ¦ ¦--']': ] [1/0] {31} + ¦ °--']': ] [0/0] {32} + °--expr: a[[ + [3/0] {33} + ¦--expr: a [0/0] {35} + ¦ °--SYMBOL: a [0/0] {34} + ¦--LBB: [[ [0/2] {36} + ¦--expr: 2 [1/0] {38} + ¦ °--NUM_CONST: 2 [0/0] {37} + ¦--']': ] [1/1] {39} + ¦--COMMENT: # [0/0] {40} + °--']': ] [1/0] {41}