From 9123afe62c582aa9e21ea0a0281be519b92bde15 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 9 Dec 2024 15:52:42 +0530 Subject: [PATCH] Improve a few function names We are being unnecessarily terse in some places where we don't need to be. I always feel like I am hitting a little speed bump every time I need to decode these names mentally. --- R/rules-indention.R | 6 ++-- R/rules-line-breaks.R | 2 +- R/rules-spaces.R | 6 ++-- R/rules-tokens.R | 4 +-- R/style-guides.R | 30 +++++++++---------- ...und_op.Rd => set_space_around_operator.Rd} | 6 ++-- ...ec.Rd => unindent_function_declaration.Rd} | 8 ++--- man/update_indention_ref.Rd | 6 ++-- ...while_for_function_multi_line_in_curly.Rd} | 6 ++-- 9 files changed, 37 insertions(+), 37 deletions(-) rename man/{set_space_around_op.Rd => set_space_around_operator.Rd} (65%) rename man/{unindent_fun_dec.Rd => unindent_function_declaration.Rd} (68%) rename man/{wrap_if_else_while_for_fun_multi_line_in_curly.Rd => wrap_if_else_while_for_function_multi_line_in_curly.Rd} (68%) diff --git a/R/rules-indention.R b/R/rules-indention.R index 3e953d76e..1439edb2a 100644 --- a/R/rules-indention.R +++ b/R/rules-indention.R @@ -16,9 +16,9 @@ indent_braces <- function(pd, indent_by) { #' Necessary for consistent indention of the function declaration header. #' @param pd A parse table. #' @inheritParams is_single_indent_function_declaration -#' @seealso set_unindention_child update_indention_ref_fun_dec +#' @seealso set_unindention_child update_indention_reference_function_declaration #' @keywords internal -unindent_fun_dec <- function(pd, indent_by = 2L) { +unindent_function_declaration <- function(pd, indent_by = 2L) { if (is_function_declaration(pd)) { idx_closing_brace <- which(pd$token == "')'") fun_dec_head <- seq2(2L, idx_closing_brace) @@ -133,7 +133,7 @@ NULL #' } #' #' @keywords internal -update_indention_ref_fun_dec <- function(pd_nested) { +update_indention_reference_function_declaration <- function(pd_nested) { if (is_function_declaration(pd_nested) && !is_single_indent_function_declaration(pd_nested)) { seq <- seq2(3L, nrow(pd_nested) - 2L) pd_nested$indention_ref_pos_id[seq] <- pd_nested$pos_id[2L] diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 5a007bdff..b091d37de 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -234,7 +234,7 @@ remove_line_break_before_round_closing_after_curly <- function(pd) { pd } -remove_line_breaks_in_fun_dec <- function(pd) { +remove_line_breaks_in_function_declaration <- function(pd) { if (is_function_declaration(pd)) { is_single_indention <- is_single_indent_function_declaration(pd) round_after <- ( diff --git a/R/rules-spaces.R b/R/rules-spaces.R index 835b25e91..57cc8dfb8 100644 --- a/R/rules-spaces.R +++ b/R/rules-spaces.R @@ -4,7 +4,7 @@ #' @include token-define.R #' @keywords internal #' @include token-define.R -set_space_around_op <- function(pd_flat, strict) { +set_space_around_operator <- function(pd_flat, strict) { # spacing and operator in same function because alternative is # calling token_is_on_aligned_line() twice because comma and operator spacing # depends on it. @@ -122,7 +122,7 @@ style_space_around_tilde <- function(pd_flat, strict) { pd_flat } -remove_space_after_unary_pm_nested <- function(pd) { +remove_space_after_unary_plus_minus_nested <- function(pd) { if (any(pd$token[1L] %in% c("'+'", "'-'"))) { pd$spaces[1L] <- 0L } @@ -349,7 +349,7 @@ remove_space_around_dollar <- function(pd_flat) { pd_flat } -remove_space_after_fun_dec <- function(pd_flat) { +remove_space_after_function_declaration <- function(pd_flat) { fun_after <- (pd_flat$token == "FUNCTION") & (pd_flat$lag_newlines == 0L) pd_flat$spaces[fun_after] <- 0L pd_flat diff --git a/R/rules-tokens.R b/R/rules-tokens.R index 1a2e857a4..ed3d3b361 100644 --- a/R/rules-tokens.R +++ b/R/rules-tokens.R @@ -64,7 +64,7 @@ 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 -wrap_if_else_while_for_fun_multi_line_in_curly <- function(pd, indent_by = 2L) { +wrap_if_else_while_for_function_multi_line_in_curly <- function(pd, indent_by = 2L) { key_token <- NULL if (is_for_expr(pd)) { @@ -88,7 +88,7 @@ wrap_if_else_while_for_fun_multi_line_in_curly <- function(pd, indent_by = 2L) { #' Wrap a multi-line statement in curly braces #' -#' @inheritParams wrap_if_else_while_for_fun_multi_line_in_curly +#' @inheritParams wrap_if_else_while_for_function_multi_line_in_curly #' @inheritParams wrap_subexpr_in_curly #' @param key_token The token that comes right before the token that contains #' the expression to be wrapped (ignoring comments). For if and while loops, diff --git a/R/style-guides.R b/R/style-guides.R index 51e758c2c..6a5366c52 100644 --- a/R/style-guides.R +++ b/R/style-guides.R @@ -76,13 +76,13 @@ tidyverse_style <- function(scope = "tokens", indention_manipulators <- if ("indention" %in% scope) { list( indent_braces = partial(indent_braces, indent_by = indent_by), - unindent_fun_dec = unindent_fun_dec, + unindent_function_declaration = unindent_function_declaration, indent_op = partial(indent_op, indent_by = indent_by), indent_eq_sub = partial(indent_eq_sub, indent_by = indent_by), indent_without_paren = partial(indent_without_paren, indent_by = indent_by ), - update_indention_ref_fun_dec = update_indention_ref_fun_dec + update_indention_reference_function_declaration = update_indention_reference_function_declaration ) } space_manipulators <- if ("spaces" %in% scope) { @@ -102,19 +102,19 @@ tidyverse_style <- function(scope = "tokens", style_space_around_tilde, strict = strict ), - spacing_around_op = purrr::partial(set_space_around_op, + spacing_around_op = purrr::partial(set_space_around_operator, strict = strict ), remove_space_after_opening_paren = remove_space_after_opening_paren, remove_space_after_excl = remove_space_after_excl, set_space_after_bang_bang = set_space_after_bang_bang, remove_space_around_dollar = remove_space_around_dollar, - remove_space_after_fun_dec = remove_space_after_fun_dec, + remove_space_after_function_declaration = remove_space_after_function_declaration, remove_space_around_colons = remove_space_around_colons, start_comments_with_space = partial(start_comments_with_space, force_one = start_comments_with_one_space ), - remove_space_after_unary_pm_nested = remove_space_after_unary_pm_nested, + remove_space_after_unary_plus_minus_nested = remove_space_after_unary_plus_minus_nested, spacing_before_comments = if (strict) { set_space_before_comments } else { @@ -137,8 +137,8 @@ tidyverse_style <- function(scope = "tokens", set_line_break_before_curly_opening = set_line_break_before_curly_opening, remove_line_break_before_round_closing_after_curly = if (strict) remove_line_break_before_round_closing_after_curly, - remove_line_breaks_in_fun_dec = - if (strict) remove_line_breaks_in_fun_dec, + remove_line_breaks_in_function_declaration = + if (strict) remove_line_breaks_in_function_declaration, set_line_breaks_between_top_level_exprs = if (strict) set_line_breaks_between_top_level_exprs, style_line_break_around_curly = partial( @@ -180,10 +180,10 @@ tidyverse_style <- function(scope = "tokens", force_assignment_op = force_assignment_op, resolve_semicolon = resolve_semicolon, add_brackets_in_pipe = add_brackets_in_pipe, - wrap_if_else_while_for_fun_multi_line_in_curly = + wrap_if_else_while_for_function_multi_line_in_curly = if (strict) { purrr::partial( - wrap_if_else_while_for_fun_multi_line_in_curly, + wrap_if_else_while_for_function_multi_line_in_curly, indent_by = indent_by ) } @@ -206,23 +206,23 @@ tidyverse_style <- function(scope = "tokens", remove_space_after_excl = "'!'", set_space_after_bang_bang = "'!'", remove_space_around_dollar = "'$'", - remove_space_after_fun_dec = "FUNCTION", + remove_space_after_function_declaration = "FUNCTION", remove_space_around_colons = c("':'", "NS_GET_INT", "NS_GET"), start_comments_with_space = "COMMENT", - remove_space_after_unary_pm_nested = c("'+'", "'-'"), + remove_space_after_unary_plus_minus_nested = c("'+'", "'-'"), spacing_before_comments = "COMMENT", set_space_in_curly = c("'{'", "'}'") ), indention = list( # indent_braces = c("'('", "'['", "'{'", "')'", "']'", "'}'"), - unindent_fun_dec = "FUNCTION", + unindent_function_declaration = "FUNCTION", indent_eq_sub = c("EQ_SUB", "EQ_FORMALS"), # TODO rename - update_indention_ref_fun_dec = "FUNCTION" + update_indention_reference_function_declaration = "FUNCTION" ), line_breaks = list( set_line_break_before_curly_opening = "'{'", remove_line_break_before_round_closing_after_curly = "'}'", - remove_line_breaks_in_fun_dec = "FUNCTION", + remove_line_breaks_in_function_declaration = "FUNCTION", set_line_break_around_curly_curly = "'{'", style_line_break_around_curly = "'{'", add_line_break_after_pipe = c("SPECIAL-PIPE", "PIPE") @@ -231,7 +231,7 @@ tidyverse_style <- function(scope = "tokens", resolve_semicolon = "';'", add_brackets_in_pipe = c("SPECIAL-PIPE", "PIPE"), force_assignment_op = "EQ_ASSIGN", - wrap_if_else_while_for_fun_multi_line_in_curly = c( + wrap_if_else_while_for_function_multi_line_in_curly = c( "IF", "WHILE", "FOR", "FUNCTION" ) ) diff --git a/man/set_space_around_op.Rd b/man/set_space_around_operator.Rd similarity index 65% rename from man/set_space_around_op.Rd rename to man/set_space_around_operator.Rd index c3a4502e3..f30a8d850 100644 --- a/man/set_space_around_op.Rd +++ b/man/set_space_around_operator.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/rules-spaces.R -\name{set_space_around_op} -\alias{set_space_around_op} +\name{set_space_around_operator} +\alias{set_space_around_operator} \title{Set spaces around operators} \usage{ -set_space_around_op(pd_flat, strict) +set_space_around_operator(pd_flat, strict) } \description{ Alignment is kept, if detected. diff --git a/man/unindent_fun_dec.Rd b/man/unindent_function_declaration.Rd similarity index 68% rename from man/unindent_fun_dec.Rd rename to man/unindent_function_declaration.Rd index f0209be93..49f6fc5c1 100644 --- a/man/unindent_fun_dec.Rd +++ b/man/unindent_function_declaration.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/rules-indention.R -\name{unindent_fun_dec} -\alias{unindent_fun_dec} +\name{unindent_function_declaration} +\alias{unindent_function_declaration} \title{Revert the indention of function declaration header} \usage{ -unindent_fun_dec(pd, indent_by = 2L) +unindent_function_declaration(pd, indent_by = 2L) } \arguments{ \item{pd}{A parse table.} @@ -16,6 +16,6 @@ operators such as '('.} Necessary for consistent indention of the function declaration header. } \seealso{ -set_unindention_child update_indention_ref_fun_dec +set_unindention_child update_indention_reference_function_declaration } \keyword{internal} diff --git a/man/update_indention_ref.Rd b/man/update_indention_ref.Rd index a041faead..0e305ee9c 100644 --- a/man/update_indention_ref.Rd +++ b/man/update_indention_ref.Rd @@ -2,10 +2,10 @@ % Please edit documentation in R/rules-indention.R \name{update_indention_ref} \alias{update_indention_ref} -\alias{update_indention_ref_fun_dec} +\alias{update_indention_reference_function_declaration} \title{Update the indention reference} \usage{ -update_indention_ref_fun_dec(pd_nested) +update_indention_reference_function_declaration(pd_nested) } \arguments{ \item{pd_nested}{A nested parse table.} @@ -15,7 +15,7 @@ Update the indention reference } \section{Functions}{ \itemize{ -\item \code{update_indention_ref_fun_dec()}: Updates the reference pos_id for all +\item \code{update_indention_reference_function_declaration()}: Updates the reference pos_id for all tokens in \code{pd_nested} if \code{pd_nested} contains a function declaration. Tokens inside a function declaration are are re-indented, that is, they are indented up to the level at which the token FUNCTION diff --git a/man/wrap_if_else_while_for_fun_multi_line_in_curly.Rd b/man/wrap_if_else_while_for_function_multi_line_in_curly.Rd similarity index 68% rename from man/wrap_if_else_while_for_fun_multi_line_in_curly.Rd rename to man/wrap_if_else_while_for_function_multi_line_in_curly.Rd index 29b7c06e9..5b95b29d4 100644 --- a/man/wrap_if_else_while_for_fun_multi_line_in_curly.Rd +++ b/man/wrap_if_else_while_for_function_multi_line_in_curly.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/rules-tokens.R -\name{wrap_if_else_while_for_fun_multi_line_in_curly} -\alias{wrap_if_else_while_for_fun_multi_line_in_curly} +\name{wrap_if_else_while_for_function_multi_line_in_curly} +\alias{wrap_if_else_while_for_function_multi_line_in_curly} \title{Wrap if-else, while and for statements in curly braces} \usage{ -wrap_if_else_while_for_fun_multi_line_in_curly(pd, indent_by = 2L) +wrap_if_else_while_for_function_multi_line_in_curly(pd, indent_by = 2L) } \arguments{ \item{pd}{A parse table.}