@@ -71,7 +71,7 @@ tidyverse_style <- function(scope = "tokens",
71
71
72
72
fix_quotes ,
73
73
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 ,
75
75
add_space_after_for_if_while ,
76
76
add_space_before_brace ,
77
77
remove_space_before_comma ,
@@ -105,25 +105,21 @@ tidyverse_style <- function(scope = "tokens",
105
105
line_break_manipulators <- if (scope > = " line_breaks" ) {
106
106
lst(
107
107
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 ,
110
112
partial(style_line_break_around_curly , strict ),
111
- if (strict ) {
113
+ set_line_break_after_opening_if_call_is_multi_line = if (strict )
112
114
partial(
113
115
set_line_break_after_opening_if_call_is_multi_line ,
114
116
except_token_after = " COMMENT" ,
115
117
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 )
121
120
partial(
122
121
set_line_break_before_closing_call , except_token_before = " COMMENT"
123
- )
124
- } else {
125
- identity
126
- } ,
122
+ ),
127
123
remove_line_break_in_empty_fun_call ,
128
124
add_line_break_after_pipe
129
125
)
@@ -135,20 +131,21 @@ tidyverse_style <- function(scope = "tokens",
135
131
resolve_semicolon ,
136
132
add_brackets_in_pipe ,
137
133
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
139
136
)
140
137
}
141
138
142
139
143
140
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
147
144
)
148
145
149
146
create_style_guide(
150
147
# transformer functions
151
- initialize = default_style_guide_attributes ,
148
+ initialize = lst( default_style_guide_attributes ) ,
152
149
line_break = line_break_manipulators ,
153
150
space = space_manipulators ,
154
151
token = token_manipulators ,
@@ -166,7 +163,7 @@ tidyverse_style <- function(scope = "tokens",
166
163
# ' transformer function corresponds to one styling rule. The output of this
167
164
# ' function can be used as an argument for \code{style} in top level functions
168
165
# ' 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
170
167
# ' variables on each level of nesting.
171
168
# ' @param line_break A list of transformer functions that manipulate line_break
172
169
# ' information.
@@ -188,8 +185,9 @@ tidyverse_style <- function(scope = "tokens",
188
185
# ' create_style_guide(line_break = set_line_break_before_curly_opening)
189
186
# ' }
190
187
# ' style_text("a <- function(x) { x }", style = set_line_break_before_curly_opening_style)
188
+ # ' @importFrom purrr compact
191
189
# ' @export
192
- create_style_guide <- function (initialize = default_style_guide_attributes ,
190
+ create_style_guide <- function (initialize = lst( default_style_guide_attributes ) ,
193
191
line_break = NULL ,
194
192
space = NULL ,
195
193
token = NULL ,
@@ -206,7 +204,8 @@ create_style_guide <- function(initialize = default_style_guide_attributes,
206
204
# transformer options
207
205
use_raw_indention ,
208
206
reindention
209
- )
207
+ ) %> %
208
+ map(compact )
210
209
}
211
210
212
211
0 commit comments