Skip to content

Commit 05c76f4

Browse files
Merge branch 'main' into split-roxygen-exec
2 parents a1589a4 + 2218546 commit 05c76f4

13 files changed

+88
-86
lines changed

.lintr

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
linters: linters_with_defaults(
2-
commented_code_linter = NULL,
3-
cyclocomp_linter = cyclocomp_linter(40),
4-
fixed_regex_linter = NULL,
5-
function_argument_linter = NULL,
6-
indentation_linter = NULL,
7-
line_length_linter(120),
8-
namespace_linter = NULL,
9-
nested_ifelse_linter = NULL,
10-
object_name_linter = NULL,
11-
object_length_linter(70),
12-
object_usage_linter = NULL,
13-
todo_comment_linter = NULL,
14-
extraction_operator_linter = NULL,
15-
nonportable_path_linter = NULL,
16-
string_boundary_linter = NULL,
17-
undesirable_function_linter = NULL,
18-
undesirable_operator_linter = NULL,
19-
defaults = linters_with_tags(tags = NULL)
20-
)
1+
linters: linters_with_tags(
2+
tags = NULL,
3+
commented_code_linter = NULL,
4+
cyclocomp_linter = cyclocomp_linter(40),
5+
fixed_regex_linter = NULL,
6+
function_argument_linter = NULL,
7+
indentation_linter = NULL,
8+
line_length_linter(120L),
9+
namespace_linter = NULL,
10+
nested_ifelse_linter = NULL,
11+
# TODO: remove this once the lint message is fixed
12+
nzchar_linter = NULL,
13+
object_name_linter = NULL,
14+
object_length_linter(70L),
15+
object_overwrite_linter = NULL,
16+
object_usage_linter = NULL,
17+
todo_comment_linter = NULL,
18+
extraction_operator_linter = NULL,
19+
nonportable_path_linter = NULL,
20+
string_boundary_linter = NULL,
21+
undesirable_function_linter = NULL,
22+
undesirable_operator_linter = NULL
23+
)
2124
exclusions: list(
22-
"inst",
23-
"man",
24-
"tests",
25-
"touchstone",
26-
"vignettes"
27-
)
25+
"inst",
26+
"man",
27+
"tests",
28+
"touchstone",
29+
"vignettes"
30+
)

R/detect-alignment-utils.R

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ alignment_drop_comments <- function(pd_by_line) {
3232
out <- vec_slice(x, x$token != "COMMENT")
3333
if (nrow(out) < 1L) {
3434
return(NULL)
35-
} else {
36-
out
3735
}
36+
out
3837
}) %>%
3938
compact()
4039
}
@@ -82,22 +81,22 @@ alignment_ensure_trailing_comma <- function(pd_by_line) {
8281
last_pd$spaces[nrow(last_pd)] <- 0L
8382
if (last(last_pd$token) == "','") {
8483
return(pd_by_line)
85-
} else {
86-
tokens <- create_tokens(
87-
tokens = "','",
88-
texts = ",",
89-
lag_newlines = 0L,
90-
spaces = 0L,
91-
pos_ids = NA,
92-
stylerignore = last_pd$stylerignore[1L],
93-
indents = last_pd$indent[1L]
94-
)
95-
tokens$.lag_spaces <- 0L
96-
97-
tokens$lag_newlines <- tokens$pos_id <- NULL
98-
pd_by_line[[length(pd_by_line)]] <- rbind(last_pd, tokens)
99-
pd_by_line
10084
}
85+
86+
tokens <- create_tokens(
87+
tokens = "','",
88+
texts = ",",
89+
lag_newlines = 0L,
90+
spaces = 0L,
91+
pos_ids = NA,
92+
stylerignore = last_pd$stylerignore[1L],
93+
indents = last_pd$indent[1L]
94+
)
95+
tokens$.lag_spaces <- 0L
96+
97+
tokens$lag_newlines <- tokens$pos_id <- NULL
98+
pd_by_line[[length(pd_by_line)]] <- rbind(last_pd, tokens)
99+
pd_by_line
101100
}
102101

103102
#' Checks if all arguments of column 1 are named
@@ -161,9 +160,8 @@ alignment_serialize <- function(pd_sub) {
161160
}, pd_sub$terminal, pd_sub$text, pd_sub$child, pd_sub$spaces, pd_sub$newlines)
162161
if (anyNA(out)) {
163162
return(NA)
164-
} else {
165-
paste0(out, collapse = "")
166163
}
164+
paste0(out, collapse = "")
167165
}
168166

169167
#' Check if spacing around comma is correct

R/detect-alignment.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ token_is_on_aligned_line <- function(pd_flat) {
101101
if (length(pd_by_line) < 1L) {
102102
return(TRUE)
103103
}
104-
pd_by_line <- alignment_drop_last_expr(pd_by_line) %>%
104+
pd_by_line <- pd_by_line %>%
105+
alignment_drop_last_expr() %>%
105106
alignment_ensure_no_closing_brace(last_line_is_closing_brace_only)
106107

107-
pd_by_line <- pd_by_line %>%
108-
alignment_ensure_trailing_comma()
108+
pd_by_line <- alignment_ensure_trailing_comma(pd_by_line)
109109
# now, pd only contains arguments separated by values, ideal for iterating
110110
# over columns.
111111
n_cols <- map_int(pd_by_line, ~ sum(.x$token == "','"))

R/io.R

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@ transform_utf8_one <- function(path, fun, dry) {
3131
identical_content <- identical(file_with_info$text, new)
3232
identical <- identical_content && !file_with_info$missing_EOF_line_break
3333
if (!identical) {
34-
if (dry == "fail") {
35-
rlang::abort(
34+
switch(dry,
35+
fail = rlang::abort(
3636
paste0(
3737
"File `", path, "` would be modified by styler and argument dry",
3838
" is set to 'fail'."
3939
),
4040
class = "dryError"
41-
)
42-
} else if (dry == "on") {
43-
# don't do anything
44-
} else if (dry == "off") {
45-
write_utf8(new, path)
46-
} else {
47-
# not implemented
48-
}
41+
),
42+
on = {
43+
# don't do anything
44+
},
45+
off = write_utf8(new, path),
46+
{
47+
# not implemented
48+
}
49+
)
4950
}
5051
!identical
5152
},
5253
error = function(e) {
5354
if (inherits(e, "dryError")) {
5455
rlang::abort(conditionMessage(e))
55-
} else {
56-
warn(paste0("When processing ", path, ": ", conditionMessage(e)))
5756
}
57+
warn(paste0("When processing ", path, ": ", conditionMessage(e)))
5858
NA
5959
}
6060
)
@@ -103,7 +103,8 @@ read_utf8_bare <- function(con, warn = TRUE) {
103103
"The file ", con, " is not encoded in UTF-8. ",
104104
"These lines contain invalid UTF-8 characters: "
105105
),
106-
toString(c(utils::head(i), if (n > 6L) "..."))
106+
toString(c(utils::head(i), if (n > 6L) "...")),
107+
call. = FALSE
107108
)
108109
}
109110
x

R/nested-to-tree.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,8 @@ create_node_from_nested <- function(pd_nested, parent, structure_only) {
6666
if (is.null(pd_nested)) {
6767
return()
6868
}
69-
7069
node_info <- create_node_info(pd_nested, structure_only)
71-
72-
child_nodes <-
73-
node_info %>%
74-
map(parent$AddChild)
75-
70+
child_nodes <- map(node_info, parent$AddChild)
7671
map2(pd_nested$child, child_nodes, create_node_from_nested, structure_only)
7772
}
7873

R/parse.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ get_parse_data <- function(text, include_text = TRUE, ...) {
102102
))
103103
}
104104
}
105-
pd <- pd %>%
106-
add_id_and_short()
105+
pd <- add_id_and_short(pd)
107106

108107
pd
109108
}

R/roxygen-examples.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ style_roxygen_code_example_one <- function(example_one,
4646
}
4747
)
4848
}
49-
unmasked %>%
50-
add_roxygen_mask(example_one, bare$example_type)
49+
add_roxygen_mask(unmasked, example_one, bare$example_type)
5150
}
5251

5352
#' Style a roxygen code example segment
@@ -118,8 +117,9 @@ style_roxygen_example_snippet <- function(code_snippet,
118117
)
119118
)
120119
if (!is_cached || !cache_is_active) {
121-
code_snippet <- code_snippet %>%
120+
code_snippet <-
122121
parse_transform_serialize_r(
122+
code_snippet,
123123
transformers,
124124
base_indention = base_indention,
125125
warn_empty = FALSE,

R/rules-spaces.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ style_space_around_math_token <- function(strict, zero, one, pd_flat) {
5858
# We remove spaces for zero (e.g., around ^ in the tidyverse style guide)
5959
# even for strict = FALSE to be consistent with the : operator
6060
if (any(pd_flat$token %in% zero)) {
61-
pd_flat <- pd_flat %>%
61+
pd_flat <-
6262
style_space_around_token(
63+
pd_flat,
6364
strict = TRUE, tokens = zero, level_before = 0L, level_after = 0L
6465
)
6566
}
6667
if (any(pd_flat$token %in% one)) {
67-
pd_flat <- pd_flat %>%
68+
pd_flat <-
6869
style_space_around_token(
70+
pd_flat,
6971
strict = strict, tokens = one, level_before = 1L, level_after = 1L
7072
)
7173
}

R/rules-tokens.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ wrap_if_else_while_for_fun_multi_line_in_curly <- function(pd, indent_by = 2L) {
8181
)
8282
}
8383
if (is_conditional_expr(pd)) {
84-
pd <- pd %>%
85-
wrap_else_multiline_curly(indent_by, space_after = 0L)
84+
pd <- wrap_else_multiline_curly(pd, indent_by, space_after = 0L)
8685
}
8786
pd
8887
}

R/transform-files.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ make_transformer <- function(transformers,
119119
if (use_cache) {
120120
text
121121
} else {
122-
transformed_code <- text %>%
122+
transformed_code <-
123123
parse_transform_serialize_r(
124+
text,
124125
transformers,
125126
base_indention = base_indention,
126127
warn_empty = warn_empty

0 commit comments

Comments
 (0)