Skip to content

Commit 7e8b667

Browse files
use NULL instead of identity()
and filter with purrr:::compact(). Requires breaking API change since initializer are now not a function anymore but a list of funcitons.
1 parent c51eef7 commit 7e8b667

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

API

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Exported functions
44

5-
create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
5+
create_style_guide(initialize = lst(default_style_guide_attributes), line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
66
default_style_guide_attributes(pd_flat)
77
specify_math_token_spacing(zero = NULL, one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
88
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export(tidyverse_reindention)
1414
export(tidyverse_style)
1515
import(tibble)
1616
importFrom(magrittr,"%>%")
17+
importFrom(purrr,compact)
1718
importFrom(purrr,flatten)
1819
importFrom(purrr,flatten_chr)
1920
importFrom(purrr,flatten_int)

R/style_guides.R

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tidyverse_style <- function(scope = "tokens",
7171

7272
fix_quotes,
7373
remove_space_before_closing_paren,
74-
if (strict) remove_space_before_opening_paren else identity,
74+
remove_space_before_opening_paren = if (strict) remove_space_before_opening_paren,
7575
add_space_after_for_if_while,
7676
add_space_before_brace,
7777
remove_space_before_comma,
@@ -105,25 +105,21 @@ tidyverse_style <- function(scope = "tokens",
105105
line_break_manipulators <- if (scope >= "line_breaks") {
106106
lst(
107107
remove_line_break_before_curly_opening,
108-
if (strict) remove_line_break_before_round_closing_after_curly else identity,
109-
if (strict) remove_line_break_before_round_closing_fun_dec else identity,
108+
remove_line_break_before_round_closing_after_curly =
109+
if (strict) remove_line_break_before_round_closing_after_curly,
110+
remove_line_break_before_round_closing_fun_dec =
111+
if (strict) remove_line_break_before_round_closing_fun_dec,
110112
partial(style_line_break_around_curly, strict),
111-
if (strict) {
113+
set_line_break_after_opening_if_call_is_multi_line = if (strict)
112114
partial(
113115
set_line_break_after_opening_if_call_is_multi_line,
114116
except_token_after = "COMMENT",
115117
except_text_before = c("switch", "ifelse", "if_else")
116-
)
117-
} else {
118-
identity
119-
} ,
120-
if (strict) {
118+
),
119+
set_line_break_before_closing_call = if (strict)
121120
partial(
122121
set_line_break_before_closing_call, except_token_before = "COMMENT"
123-
)
124-
} else {
125-
identity
126-
} ,
122+
),
127123
remove_line_break_in_empty_fun_call,
128124
add_line_break_after_pipe
129125
)
@@ -135,20 +131,21 @@ tidyverse_style <- function(scope = "tokens",
135131
resolve_semicolon,
136132
add_brackets_in_pipe,
137133
remove_terminal_token_before_and_after,
138-
if (strict) wrap_if_else_multi_line_in_curly else identity
134+
wrap_if_else_multi_line_in_curly =
135+
if (strict) wrap_if_else_multi_line_in_curly
139136
)
140137
}
141138

142139

143140
indention_modifier <-
144-
c(
145-
if (scope >= "indention") update_indention_ref_fun_dec,
146-
identity
141+
lst(
142+
update_indention_ref_fun_dec =
143+
if (scope >= "indention") update_indention_ref_fun_dec
147144
)
148145

149146
create_style_guide(
150147
# transformer functions
151-
initialize = default_style_guide_attributes,
148+
initialize = lst(default_style_guide_attributes),
152149
line_break = line_break_manipulators,
153150
space = space_manipulators,
154151
token = token_manipulators,
@@ -166,7 +163,7 @@ tidyverse_style <- function(scope = "tokens",
166163
#' transformer function corresponds to one styling rule. The output of this
167164
#' function can be used as an argument for \code{style} in top level functions
168165
#' like [style_text()] and friends.
169-
#' @param initialize The bare name of a function that initializes various
166+
#' @param initialize A list of functions that initializes various
170167
#' variables on each level of nesting.
171168
#' @param line_break A list of transformer functions that manipulate line_break
172169
#' information.
@@ -188,8 +185,9 @@ tidyverse_style <- function(scope = "tokens",
188185
#' create_style_guide(line_break = set_line_break_before_curly_opening)
189186
#' }
190187
#' style_text("a <- function(x) { x }", style = set_line_break_before_curly_opening_style)
188+
#' @importFrom purrr compact
191189
#' @export
192-
create_style_guide <- function(initialize = default_style_guide_attributes,
190+
create_style_guide <- function(initialize = lst(default_style_guide_attributes),
193191
line_break = NULL,
194192
space = NULL,
195193
token = NULL,
@@ -206,7 +204,8 @@ create_style_guide <- function(initialize = default_style_guide_attributes,
206204
# transformer options
207205
use_raw_indention,
208206
reindention
209-
)
207+
) %>%
208+
map(compact)
210209
}
211210

212211

man/create_style_guide.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)