Skip to content

Commit 0a39e78

Browse files
creating tokens must respect stylerignore
1 parent 7175da0 commit 0a39e78

File tree

5 files changed

+286
-3
lines changed

5 files changed

+286
-3
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
* Piped function without brackets `substitute(x %>% y)` don't get `()` added
2929
anymore, as this can change outcome of the code (#876).
30+
* rules that add tokens don't break stylerignore sequences anymore (#891).
3031
* Add vignette on distributing style guide (#846, #861).
3132
* Alignment detection respects stylerignore (#850).
3233
* `Warning: Unknown or uninitialised column:` was fixed (#885).
@@ -35,9 +36,9 @@
3536
* ensure a trailing blank line also if the input is cached (#867).
3637
* Preserve trailing blank line in roxygen examples to simplify concatenation of
3738
examples (#880).
38-
* Fix argument name `filetype` in Example for `style_dir()` (#855).
3939
* An error is now thrown on styling if input unicode characters can't be
4040
correctly parsed for Windows and R < 4.2 (#883).
41+
* Fix argument name `filetype` in Example for `style_dir()` (#855).
4142

4243

4344
**Infrastructure**

R/rules-tokens.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ add_brackets_in_pipe_one <- function(pd, pos) {
3535
child <- pd$child[[next_non_comment]]
3636
new_pos_ids <- create_pos_ids(child, 1, after = TRUE, n = 2)
3737
new_pd <- create_tokens(
38-
tokens = c("'('", "')'"),
3938
texts = c("(", ")"),
39+
lag_newlines = rep(0L, 2),
40+
spaces = 0,
4041
pos_ids = new_pos_ids,
41-
lag_newlines = rep(0L, 2)
42+
token_before = c(child$token[1], "'('"),
43+
token_after = c("')'", child$token_after[1]),
44+
indention_ref_pos_ids = NA,
45+
indents = child$indent[1],
46+
tokens = c("'('", "')'"),
47+
terminal = TRUE,
48+
child = NULL,
49+
stylerignore = child$stylerignore[1],
50+
# block???
51+
block = NA,
52+
is_cached = FALSE
4253
)
4354
pd$child[[next_non_comment]] <- bind_rows(
4455
pd$child[[next_non_comment]],
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# styler: off
2+
aflh({
3+
isfris %>%
4+
# comment
5+
tjnfaxasf12af7987A() %>% # comment
6+
tjnfaxdfaasfaf7987A() %>%
7+
tjnfxasfaf798fA() %>%
8+
tf797A() %>% # more
9+
# comment
10+
yyexprzB()
11+
})
12+
# styler: on
13+
14+
15+
aflh({
16+
isfris %>%
17+
# comment
18+
tjnfaxasf12af7987A() %>% # comment
19+
tjnfaxdfaasfaf7987A() %>%
20+
tjnfxasfaf798fA() %>%
21+
tf797A() %>% # more
22+
# comment
23+
yyexprzB()
24+
})
25+
26+
27+
# styler: off
28+
aflh({
29+
isfris %>%
30+
# comment
31+
tjnfaxasf12af7987A %>%
32+
tjnfaxdfaasfaf7987A %>%
33+
tjnfxasfaf798fA %>%
34+
# more
35+
tf797A %>% # comments
36+
# here
37+
yyexprzB #
38+
# whatnot
39+
})
40+
# styler: on
41+
42+
43+
aflh({
44+
isfris %>%
45+
# comment
46+
tjnfaxasf12af7987A %>%
47+
tjnfaxdfaasfaf7987A %>%
48+
tjnfxasfaf798fA %>%
49+
# more
50+
tf797A %>% # comments
51+
# here
52+
yyexprzB #
53+
# whatnot
54+
})

tests/testthat/token_adding_removing/add_brackets_in_pipe-stylerignore-in_tree

Lines changed: 163 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# styler: off
2+
aflh({
3+
isfris %>%
4+
# comment
5+
tjnfaxasf12af7987A() %>% # comment
6+
tjnfaxdfaasfaf7987A() %>%
7+
tjnfxasfaf798fA() %>%
8+
tf797A() %>% # more
9+
# comment
10+
yyexprzB()
11+
})
12+
# styler: on
13+
14+
15+
aflh({
16+
isfris %>%
17+
# comment
18+
tjnfaxasf12af7987A() %>% # comment
19+
tjnfaxdfaasfaf7987A() %>%
20+
tjnfxasfaf798fA() %>%
21+
tf797A() %>% # more
22+
# comment
23+
yyexprzB()
24+
})
25+
26+
27+
# styler: off
28+
aflh({
29+
isfris %>%
30+
# comment
31+
tjnfaxasf12af7987A %>%
32+
tjnfaxdfaasfaf7987A %>%
33+
tjnfxasfaf798fA %>%
34+
# more
35+
tf797A %>% # comments
36+
# here
37+
yyexprzB #
38+
# whatnot
39+
})
40+
# styler: on
41+
42+
43+
aflh({
44+
isfris %>%
45+
# comment
46+
tjnfaxasf12af7987A() %>%
47+
tjnfaxdfaasfaf7987A() %>%
48+
tjnfxasfaf798fA() %>%
49+
# more
50+
tf797A() %>% # comments
51+
# here
52+
yyexprzB() #
53+
# whatnot
54+
})

0 commit comments

Comments
 (0)