Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve a few function names #1249

Merged
merged 1 commit into from
Dec 9, 2024
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
6 changes: 3 additions & 3 deletions R/rules-indention.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion R/rules-line-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <- (
Expand Down
6 changes: 3 additions & 3 deletions R/rules-spaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/rules-tokens.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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,
Expand Down
30 changes: 15 additions & 15 deletions R/style-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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
)
}
Expand All @@ -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")
Expand All @@ -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"
)
)
Expand Down

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

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

6 changes: 3 additions & 3 deletions man/update_indention_ref.Rd

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

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

Loading