@@ -33,7 +33,7 @@ There are three major steps that styler performs in order to style code:
33
33
the nested parse table and add spaces and line breaks between them as
34
34
specified in the nested parse table.
35
35
36
- The argument transformers is, apart from the code to style, the key argument
36
+ The ` transformers ` argument is, apart from the code to style, the key argument
37
37
of functions such as ` style_text() ` and friends. By default, it is created
38
38
via the argument ` style ` . The transformers are a named
39
39
list of transformer functions and other arguments passed to styler. To use the
@@ -144,7 +144,7 @@ four attributes in total: `lag_newlines`, `newlines`, `spaces`, `lag_spaces`.
144
144
` lag_spaces ` is created from ` spaces ` only just before the parse table is
145
145
serialized, so it is not relevant for manipulating the parse table as
146
146
described above. These columns are to some degree redundant, but with just lag
147
- or lead, we would loose information on the first or the last element
147
+ or lead, we would lose information on the first or the last element
148
148
respectively, so we need both.
149
149
150
150
The sequence in which styler applies rules on each level of nesting
@@ -179,6 +179,10 @@ rules. For development purposes, you also may want to use the unexported
179
179
function ` test_collection() ` to help you with testing your style guide. You can
180
180
find more information in the help file of the function.
181
181
182
+ If you write functions that modify spaces, don't forget make sure
183
+ you don't modify EOL spacing, since that is needed for ` use_raw_indention ` , as
184
+ indicated in the previous paragraph.
185
+
182
186
Finally, take note of the naming convention. All function names starting with
183
187
` set-* ` correspond to the ` strict ` option, that is, setting some value to an
184
188
exact number. ` add-* ` Is softer: For example, ` add_spaces_around_op() ` , only
@@ -242,12 +246,9 @@ Now you can style your string according to it.
242
246
``` {r}
243
247
style_text(code, style = set_line_break_before_curly_opening_style)
244
248
```
245
- Note that:
246
249
247
- * We have not implemented a rule that sets the line breaks before the curly
248
- opening brace, which you probably want to for the above rule to be complete.
249
- * Note that when removing line breaks, always take care of comments, since you
250
- don't want this
250
+ Note that when removing line breaks, always take care of comments, since you
251
+ don't want
251
252
``` {r, eval = FALSE}
252
253
a <- function() # comments should remain EOL
253
254
{
@@ -263,6 +264,11 @@ a <- function() # comments should remain EOL {
263
264
}
264
265
```
265
266
266
- The easiest way of taking care of that is not applying the rule
267
- if there is a comment, which can be checked for within your transformer
268
- function.
267
+ The easiest way of taking care of that is not applying the rule if there is a
268
+ comment before the token of interest, which can be checked for within your
269
+ transformer function. The transformer function from the tidyverse style that
270
+ removes line breaks before the curly opening bracket looks as follows:
271
+ ``` {r}
272
+ styler:::remove_line_break_before_curly_opening
273
+ ```
274
+
0 commit comments