Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down
9 changes: 1 addition & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
11 changes: 3 additions & 8 deletions R/addins.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
NULL


#' @importFrom rlang abort

#' @keywords internal
style_active_file <- function() {
communicate_addins_style_transformers()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 <-
Expand All @@ -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(
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions R/communicate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
5 changes: 2 additions & 3 deletions R/compat-dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}
14 changes: 4 additions & 10 deletions R/detect-alignment-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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", ]
Expand Down Expand Up @@ -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) {
Expand All @@ -124,15 +121,13 @@ 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)
}

#' Serialize one line for a column
#'
#'
#' @inheritParams alignment_serialize_column
#' @inheritParams alignment_col1_all_named
#' @keywords internal
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 == "','")
Expand All @@ -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)
}
2 changes: 0 additions & 2 deletions R/detect-alignment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 3 additions & 4 deletions R/indent.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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]")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions R/initialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
)
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions R/io.R
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 0 additions & 2 deletions R/nested-to-tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>%
Expand Down Expand Up @@ -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)) {
Expand Down
13 changes: 5 additions & 8 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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) %>%
Expand Down Expand Up @@ -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)
)
Expand All @@ -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
)

Expand Down
Loading