Skip to content

Commit d829284

Browse files
authored
Merge branch 'main' into f-759-named-funs
2 parents e35bc18 + 08da821 commit d829284

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+193
-231
lines changed

API

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ cache_info(cache_name = NULL, format = "both")
99
create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention(), style_guide_name = NULL, style_guide_version = NULL, more_specs_style_guide = NULL, transformers_drop = specify_transformers_drop(), indent_character = " ")
1010
default_style_guide_attributes(pd_flat)
1111
specify_math_token_spacing(zero = "'^'", one = c("'+'", "'-'", "'*'", "'/'"))
12-
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
12+
specify_reindention(regex_pattern = NULL, indention = 0L, comments_only = TRUE)
1313
specify_transformers_drop(spaces = NULL, indention = NULL, line_breaks = NULL, tokens = NULL)
14-
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"), recursive = TRUE, exclude_files = NULL, exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0, dry = "off")
15-
style_file(path, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0, dry = "off")
16-
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"), exclude_files = c("R/RcppExports.R", "R/cpp11.R"), exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0, dry = "off")
14+
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"), recursive = TRUE, exclude_files = NULL, exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
15+
style_file(path, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
16+
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile", "Rmd", "Rmarkdown", "Rnw", "Qmd"), exclude_files = c("R/RcppExports.R", "R/cpp11.R"), exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0L, dry = "off")
1717
style_text(text, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0)
1818
tidyverse_math_token_spacing()
1919
tidyverse_reindention()

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: styler
33
Title: Non-Invasive Pretty Printing of R Code
4-
Version: 1.7.0.9001
4+
Version: 1.7.0.9002
55
Authors@R:
66
c(person(given = "Kirill",
77
family = "Müller",

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ importFrom(purrr,flatten_int)
2929
importFrom(purrr,map)
3030
importFrom(purrr,map2)
3131
importFrom(purrr,map2_chr)
32-
importFrom(purrr,map2_lgl)
3332
importFrom(purrr,map_at)
3433
importFrom(purrr,map_chr)
3534
importFrom(purrr,map_int)

NEWS.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
---
2-
editor_options:
3-
markdown:
4-
wrap: 79
5-
---
1+
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->
62

7-
# styler 1.7.0.9000 (Development version)
3+
# styler 1.7.0.9002 (Development version)
4+
5+
- Same as previous version.
6+
7+
8+
# styler 1.7.0.9000
89

910
**User-facing changes**
1011

11-
- `style_dir()` and `style_pkg()` now default to styling all supported file
12-
formats (`.R`, `.Rmd`, `.Rmarkdown`, `.Rnw`, and `.qmd`) in the (package)
13-
directory (\@IndrajeetPatil, #965).
14-
- `style_pkg()` now excludes the auto-generated `R/cpp11.R` file (#977).
12+
- `style_dir()` and `style_pkg()` now default to styling all supported file
13+
formats (`.R`, `.Rmd`, `.Rmarkdown`, `.Rnw`, and `.qmd`) in the (package)
14+
directory (\@IndrajeetPatil, #965, #931).
15+
- `style_pkg()` now excludes the auto-generated `R/cpp11.R` file (#977).
1516
- Minimum needed R version is now bumped to `3.5` (\@IndrajeetPatil, #986).
1617

1718
**Features**
1819

19-
- `filetype` `.qmd` is now supported, but not turned on by default (#931).
2020
- alignment is now detected for function declaration in a similar way as for
2121
function calls (#968).
2222
- new R option `styler.ignore_alignment` controls if alignment should be
@@ -29,7 +29,7 @@ editor_options:
2929

3030
- If there are only empty lines in a code chunk, they are all removed (#936).
3131

32-
- There is now always one line break after `{` and before `#` (#916).
32+
- There is now always one line break after `{` and before `#` (#952).
3333

3434
- Line breaks may be added to function calls to ensure indention symmetry for
3535
round braces (#975).
@@ -52,20 +52,24 @@ editor_options:
5252

5353
- \@IndrajeetPatil is now a contributor to {styler}. Welcome and thanks for
5454
everything you did so far! (#988).
55-
- Non-exported and unused functions `odd()` and `even()` were removed
56-
(\@IndrajeetPatil, #989).
5755
- Old (and outdated) vignettes have been removed (\@IndrajeetPatil, #955). To
5856
access them, do `git checkout v1.0.0`.
59-
- Upgrade testing infra to testthat 3e (\@IndrajeetPatil, #949).
6057
- Minor improvements to the documentation (\@IndrajeetPatil, #958).
58+
- turned off `styler.print.Vertical` in vignettes so ANSI output of
59+
{prettycode} not messing with {pkgdown} (\@IndrajeetPatil, #956, #957).
60+
- Non-exported and unused functions `odd()` and `even()` were removed
61+
(\@IndrajeetPatil, #989).
62+
- Upgrade testing infra to testthat 3e (\@IndrajeetPatil, #949).
6163
- All (R)md files in this project's source code are now formatted with
6264
default pandoc markdown formatter. This conversion is required when using
6365
the visual mode in RStudio (#941).
6466
- Update {pkgdown} action to always build, but only deploy on default branch
6567
(#946).
66-
- turned off `styler.print.Vertical` in vignettes so ANSI output of
67-
{prettycode} not messing with {pkgdown} (\@IndrajeetPatil, #956, #957).
68+
- Better stack tracing for profiling (#979, #980).
6869
- Improved code quality by fixing {lintr} warnings (#960).
70+
- Error now on R CMD note (\@IndrajeetPatil, #987).
71+
- Test on latest Ubuntu instead of Ubuntu 18.04 (#982).
72+
- Run tests in parallel (#978, \@krlmlr).
6973

7074
# styler 1.7.0
7175

R/addins.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ style_active_file <- function() {
5252
context <- get_rstudio_context()
5353
transformer <- make_transformer(get_addins_style_transformer(),
5454
include_roxygen_examples = TRUE,
55-
base_indention = 0,
55+
base_indention = 0L,
5656
warn_empty = is_plain_r_file(context$path)
5757
)
5858
is_r_file <- any(
@@ -71,7 +71,7 @@ style_active_file <- function() {
7171
abort("Can only style .R, .Rmd and .Rnw files.")
7272
}
7373
rstudioapi::modifyRange(
74-
c(1, 1, length(context$contents) + 1, 1),
74+
c(1L, 1L, length(context$contents) + 1L, 1L),
7575
paste0(ensure_last_n_empty(out), collapse = "\n"),
7676
id = context$id
7777
)
@@ -124,7 +124,7 @@ style_selection <- function() {
124124
communicate_addins_style_transformers()
125125
context <- get_rstudio_context()
126126
text <- context$selection[[1]]$text
127-
if (all(nchar(text) == 0)) abort("No code selected")
127+
if (all(nchar(text) == 0L)) abort("No code selected")
128128
out <- style_text(
129129
text,
130130
transformers = get_addins_style_transformer(),
@@ -134,7 +134,7 @@ style_selection <- function() {
134134
context$selection[[1]]$range,
135135
paste0(c(
136136
out,
137-
if (context$selection[[1]]$range$end[2] == 1) ""
137+
if (context$selection[[1]]$range$end[2] == 1L) ""
138138
), collapse = "\n"),
139139
id = context$id
140140
)

R/compat-dplyr.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ left_join <- function(x, y, by) {
6565
res <- new_tibble(res, nrow = nrow(res))
6666
# dplyr::left_join set unknown list columns to NULL, merge sets them
6767
# to NA
68-
if (exists("child", res) && any(is.na(res$child))) {
68+
if (exists("child", res) && anyNA(res$child)) {
6969
res$child[is.na(res$child)] <- list(NULL)
7070
}
7171
res
@@ -80,6 +80,7 @@ slice <- function(.data, ...) {
8080
.data[c(...), , drop = FALSE]
8181
}
8282

83+
# TODO: Use `purrr::map_dfr()` when it stops implicitly relying on `{dplyr}`
8384
#' @importFrom purrr as_mapper map
8485
map_dfr <- function(.x, .f, ..., .id = NULL) {
8586
.f <- as_mapper(.f, ...)

R/detect-alignment-utils.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ alignment_ensure_no_closing_brace <- function(pd_by_line,
3232
alignment_drop_comments <- function(pd_by_line) {
3333
map(pd_by_line, function(x) {
3434
out <- x[x$token != "COMMENT", ]
35-
if (nrow(out) < 1) {
35+
if (nrow(out) < 1L) {
3636
return(NULL)
3737
} else {
3838
out
@@ -111,14 +111,12 @@ alignment_ensure_trailing_comma <- function(pd_by_line) {
111111
#' @keywords internal
112112
alignment_col1_all_named <- function(relevant_pd_by_line) {
113113
map_lgl(relevant_pd_by_line, function(x) {
114-
if (nrow(x) < 3) {
114+
if (nrow(x) < 3L) {
115115
return(FALSE)
116116
}
117117
x$token[3] == "expr" &&
118-
x$token[1] %in% c("SYMBOL_SUB", "STR_CONST", "SYMBOL_FORMALS") &&
119-
x$token[2] %in% c(
120-
"EQ_SUB", "EQ_FORMALS", "SPECIAL-IN", "LT", "GT", "EQ", "NE"
121-
)
118+
any(c("SYMBOL_SUB", "STR_CONST", "SYMBOL_FORMALS") == x$token[1]) &&
119+
any(c("EQ_SUB", "EQ_FORMALS", "SPECIAL-IN", "LT", "GT", "EQ", "NE") == x$token[2])
122120
}) %>%
123121
all()
124122
}
@@ -184,7 +182,7 @@ alignment_serialize <- function(pd_sub) {
184182
#' @keywords internal
185183
alignment_has_correct_spacing_around_comma <- function(pd_sub) {
186184
comma_tokens <- which(pd_sub$token == "','")
187-
if (length(comma_tokens) == 0) {
185+
if (length(comma_tokens) == 0L) {
188186
return(TRUE)
189187
}
190188
relevant_comma_token <- comma_tokens[seq2(1, length(comma_tokens) - 1L)]
@@ -201,7 +199,7 @@ alignment_has_correct_spacing_around_comma <- function(pd_sub) {
201199
#' @importFrom rlang seq2
202200
alignment_has_correct_spacing_around_eq_sub <- function(pd_sub) {
203201
relevant_eq_sub_token <- which(pd_sub$token == "EQ_SUB")
204-
if (length(relevant_eq_sub_token) == 0) {
202+
if (length(relevant_eq_sub_token) == 0L) {
205203
return(TRUE)
206204
}
207205

R/detect-alignment.R

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#' transformers <- tidyverse_style()
3434
#' pd_nested <- styler:::compute_parse_data_nested(c(
3535
#' "call(",
36-
#' " ab = 1,",
36+
#' " ab = 1L,",
3737
#' " a = 2",
3838
#' ")"
3939
#' )) %>%
@@ -50,7 +50,7 @@ token_is_on_aligned_line <- function(pd_flat) {
5050
pd_flat$.lag_spaces <- lag(pd_flat$spaces)
5151
pd_by_line <- split(pd_flat, line_idx)
5252
pd_by_line[purrr::map_lgl(pd_by_line, ~ any(.x$stylerignore))] <- NULL
53-
if (length(pd_by_line) < 1) {
53+
if (length(pd_by_line) < 1L) {
5454
return(TRUE)
5555
}
5656
last_line_is_closing_brace_only <- nrow(last(pd_by_line)) == 1
@@ -93,7 +93,7 @@ token_is_on_aligned_line <- function(pd_flat) {
9393
}
9494

9595
pd_by_line <- alignment_drop_comments(pd_by_line)
96-
if (length(pd_by_line) < 1) {
96+
if (length(pd_by_line) < 1L) {
9797
return(TRUE)
9898
}
9999
pd_by_line <- alignment_drop_last_expr(pd_by_line) %>%
@@ -104,10 +104,9 @@ token_is_on_aligned_line <- function(pd_flat) {
104104
# now, pd only contains arguments separated by values, ideal for iterating
105105
# over columns.
106106
n_cols <- map_int(pd_by_line, ~ sum(.x$token == "','"))
107-
previous_line <- 0
108-
current_col <- 0
109-
start_eval <- ifelse(alignment_col1_all_named(pd_by_line), 1, 2)
110-
for (column in seq2(1, max(n_cols))) {
107+
previous_line <- current_col <- 0L
108+
start_eval <- ifelse(alignment_col1_all_named(pd_by_line), 1L, 2L)
109+
for (column in seq2(1L, max(n_cols))) {
111110
by_line <- alignment_serialize_column(pd_by_line, column) %>%
112111
compact() %>%
113112
unlist() %>%
@@ -120,7 +119,7 @@ token_is_on_aligned_line <- function(pd_flat) {
120119
current_col <- nchar(by_line) - as.integer(column > 1)
121120
# Problem `by_line` counting from comma before column 3, previous_line
122121
# counting 1 space before ~
123-
if (column > 1) {
122+
if (column > 1L) {
124123
previous_line <- previous_line[
125124
intersect(names(previous_line), names(by_line))
126125
]
@@ -129,28 +128,28 @@ token_is_on_aligned_line <- function(pd_flat) {
129128
}
130129

131130
is_aligned <- length(unique(current_col)) == 1L
132-
if (!is_aligned || length(current_col) < 2) {
131+
if (!is_aligned || length(current_col) < 2L) {
133132
# check 2: left aligned after , (comma to next token)
134133
current_col <- "^(,[\\s\\t]*)[^ ]*.*$" %>%
135134
gsub("\\1", by_line, perl = TRUE) %>%
136135
nchar() %>%
137136
magrittr::subtract(1)
138137

139-
if (column > 1) {
138+
if (column > 1L) {
140139
# must add previous columns, as first column might not align
141140
current_col <- previous_line + current_col
142141
}
143-
if (length(current_col) > 1) {
142+
if (length(current_col) > 1L) {
144143
is_aligned <- length(unique(current_col)) == 1L
145144
} else {
146-
is_aligned <- current_col - max_previous_col == 1
145+
is_aligned <- current_col - max_previous_col == 1L
147146
current_col <- max_previous_col + current_col
148147
}
149148

150149
if (is_aligned) {
151150
# if left aligned after ,
152-
start_eval <- 2
153-
previous_line <- nchar(by_line) - 1 + previous_line # comma to comma
151+
start_eval <- 2L
152+
previous_line <- nchar(by_line) - 1L + previous_line # comma to comma
154153
}
155154
} else {
156155
previous_line <- current_col
@@ -162,22 +161,22 @@ token_is_on_aligned_line <- function(pd_flat) {
162161
# match left aligned after =
163162
start_after_eq <- regexpr("= [^ ]", by_line)
164163
names(start_after_eq) <- names(by_line)
165-
start_after_eq <- start_after_eq[start_after_eq > 0]
164+
start_after_eq <- start_after_eq[start_after_eq > 0L]
166165

167166
if (column >= start_eval) {
168-
if (length(start_after_eq) == 0) {
167+
if (length(start_after_eq) == 0L) {
169168
return(FALSE)
170169
}
171170
# when match via , unsuccessful, matching by = must yield at least one =
172-
if (column == 1) {
171+
if (column == 1L) {
173172
current_col <- start_after_eq
174173
} else {
175174
current_col <- start_after_eq +
176175
previous_line[intersect(names(previous_line), names(start_after_eq))]
177176
}
178177
is_aligned <- all(
179-
length(unique(current_col)) == 1,
180-
length(start_after_eq) > 1
178+
length(unique(current_col)) == 1L,
179+
length(start_after_eq) > 1L
181180
)
182181
if (!is_aligned) {
183182
return(FALSE)

R/expr-is.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ is_subset_expr <- function(pd) {
111111
#' @keywords internal
112112
is_shebang <- function(pd) {
113113
is_first_comment <- pd$pos_id == 1L
114-
is_first_comment[is_first_comment] <- grepl(
115-
"^#!", pd$text[is_first_comment]
116-
)
114+
is_first_comment[is_first_comment] <- startsWith(pd$text[is_first_comment], "#!")
117115
is_first_comment
118116
}
119117

@@ -150,7 +148,7 @@ contains_else_expr <- function(pd) {
150148
#' @keywords internal
151149
contains_else_expr_that_needs_braces <- function(pd) {
152150
else_idx <- which(pd$token == "ELSE")
153-
if (length(else_idx) > 0) {
151+
if (length(else_idx) > 0L) {
154152
non_comment_after_else <- next_non_comment(pd, else_idx)
155153
sub_expr <- pd$child[[non_comment_after_else]]
156154
# needs braces if NOT if_condition, NOT curly expr

R/indent.R

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ indent_without_paren_for_while_fun <- function(pd, indent_by) {
2121
return(pd)
2222
}
2323

24-
if (pd$newlines[length(pd$newlines) - 1] == 0) {
24+
if (pd$newlines[length(pd$newlines) - 1] == 0L) {
2525
return(pd)
2626
}
2727
pd$indent[nrow] <- indent_by
@@ -33,9 +33,7 @@ indent_without_paren_for_while_fun <- function(pd, indent_by) {
3333
#' @keywords internal
3434
indent_without_paren_if_else <- function(pd, indent_by) {
3535
expr_after_if <- next_non_comment(pd, which(pd$token == "')'")[1])
36-
is_if <- pd$token[1] %in% "IF"
37-
has_if_without_curly <-
38-
is_if && pd$child[[expr_after_if]]$token[1] != "'{'"
36+
is_if <- pd$token[1] == "IF"
3937
if (!is_if) {
4038
return(pd)
4139
}
@@ -47,10 +45,8 @@ indent_without_paren_if_else <- function(pd, indent_by) {
4745
pd$indent[expr_after_if] <- indent_by
4846
}
4947

50-
51-
5248
else_idx <- which(pd$token == "ELSE")
53-
if (length(else_idx) == 0) {
49+
if (length(else_idx) == 0L) {
5450
return(pd)
5551
}
5652
expr_after_else_idx <- next_non_comment(pd, else_idx)
@@ -167,7 +163,7 @@ needs_indention <- function(pd,
167163
needs_indention_one <- function(pd,
168164
potential_trigger_pos,
169165
other_trigger_tokens) {
170-
before_first_break <- which(pd$lag_newlines > 0)[1] - 1L
166+
before_first_break <- which(pd$lag_newlines > 0L)[1] - 1L
171167
if (is.na(before_first_break)) {
172168
return(FALSE)
173169
}
@@ -240,7 +236,7 @@ pd_multi_line <- function(pd) {
240236
#' @seealso choose_indention
241237
#' @keywords internal
242238
update_newlines <- function(pd) {
243-
seq_pd <- seq_len(nrow(pd) - 1)
244-
pd$newlines[seq_pd] <- pd$lag_newlines[seq_pd + 1]
239+
seq_pd <- seq_len(nrow(pd) - 1L)
240+
pd$newlines[seq_pd] <- pd$lag_newlines[seq_pd + 1L]
245241
pd
246242
}

0 commit comments

Comments
 (0)