Skip to content

Commit 8027fb2

Browse files
Merge pull request #366 from lorenzwalthert/prepare-v1.0.1
- Prepare v1.0.1 (#366).
2 parents 26413c6 + f6581d7 commit 8027fb2

File tree

143 files changed

+322
-40
lines changed

Some content is hidden

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

143 files changed

+322
-40
lines changed

DESCRIPTION

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Description:
88
Imports:
99
backports,
1010
cli,
11-
enc (>= 0.1-10),
11+
enc (>= 0.2),
1212
magrittr,
1313
purrr (>= 0.2.3),
1414
rematch2,
@@ -37,26 +37,26 @@ VignetteBuilder: knitr
3737
Collate:
3838
'addins.R'
3939
'communicate.R'
40+
'compat-dplyr.R'
4041
'compat-tidyr.R'
41-
'dplyr.R'
4242
'expr-is.R'
4343
'indent.R'
4444
'initialize.R'
4545
'nest.R'
46-
'nested_to_tree.R'
46+
'nested-to-tree.R'
4747
'parse.R'
4848
'reindent.R'
4949
'token-define.R'
5050
'relevel.R'
51-
'rules-line_break.R'
51+
'rules-line-break.R'
5252
'rules-other.R'
5353
'rules-replacement.R'
5454
'rules-spacing.R'
5555
'serialize.R'
56-
'serialized_tests.R'
5756
'set-assert-args.R'
58-
'style_guides.R'
57+
'style-guides.R'
5958
'styler.R'
59+
'testing.R'
6060
'token-create.R'
6161
'transform-code.R'
6262
'transform-files.R'
@@ -66,5 +66,3 @@ Collate:
6666
'vertical.R'
6767
'visit.R'
6868
'zzz.R'
69-
Remotes:
70-

NEWS.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
## styler 1.0.1 (2018-03-02)
2+
3+
This is a maintenance release without any breaking API changes.
4+
5+
## Major & dependency related changes
6+
7+
* Removed implicit `dplyr` dependency via `purrr:::map_dfr()` (thanks
8+
@jimhester, #324).
9+
* Added required minimal version dependency for purr (`>= 0.2.3`) (#338).
10+
* We rely on the tibble package which was optimized for speed in `v1.4.2` so
11+
styler should run ~2x as fast
12+
[(#348)](https://github.com/tidyverse/tibble/pull/348). For that reason,
13+
styler now depends on `tibble >= 1.4.2`.
14+
* In the dependency `enc`, a bug was fixed that removed/changed non-ASCII
15+
characters. Hence, styler now depends on `enc >= 0.2` (#348).
16+
17+
## Minor changes
18+
19+
* We're now recognizing and respecting DSLs used in R comments: rplumnber
20+
(`#*`, #306), shebang `#/!` (#345), knitr chunk headers for spinning (`#+` /
21+
`#-`, #362).
22+
* Named arguments can stay on the first line if call is multi-line (#318).
23+
* No space anymore with `tidyverse_style()` after `!!` since with `rlang 0.2`,
24+
`!!` now binds tighter (#322), spacing around `~` (#316), no space anymore
25+
around `^` (#308).
26+
* Various bug fixes and edge case improvements.
27+
28+
Thanks to all contributors for patches, issues and the like:
29+
@devSJR, @klrmlr, @yutannihilation, @samhinshaw, @martin-mfg, @jjramsey,
30+
@RMHogervorst, @wlandau, @llrs, @aaronrudkin, @crew102, @jkgrain, @jennybc,
31+
@joranE.
32+
133
## styler 1.0.0 (2017-12-05)
234

335
Initial release.

R/addins.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ NULL
1818

1919
#' @describeIn styler_addins Styles the active file with [tidyverse_style()] and
2020
#' `strict = TRUE`.
21+
#' @keywords internal
2122
style_active_file <- function() {
2223
transformer <- make_transformer(tidyverse_style())
2324
context <- get_rstudio_context()
@@ -46,6 +47,7 @@ style_active_file <- function() {
4647
#' @param context The context from `styler:::get_rstudio_context()`.
4748
#' @param transformer A transformer function most conveniently constructed with
4849
#' [make_transformer()].
50+
#' @keywords internal
4951
try_transform_as_r_file <- function(context, transformer) {
5052
tryCatch(
5153
transformer(context$contents),
@@ -62,6 +64,7 @@ try_transform_as_r_file <- function(context, transformer) {
6264

6365
#' @describeIn styler_addins Styles the highlighted selection in a `.R` or
6466
#' `.Rmd` file.
67+
#' @keywords internal
6568
style_selection <- function() {
6669
context <- get_rstudio_context()
6770
text <- context$selection[[1]]$text

R/communicate.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#' @param changed Boolean with indicating for each file whether or not it has
66
#' been changed.
77
#' @inheritParams can_verify_roundtrip
8+
#' @keywords internal
89
communicate_warning <- function(changed, transformers) {
910
if (any(changed, na.rm = TRUE) && !can_verify_roundtrip(transformers)) {
1011
cat("Please review the changes carefully!")
@@ -16,6 +17,7 @@ communicate_warning <- function(changed, transformers) {
1617
#' @param changed Boolean with indicating for each file whether or not it has
1718
#' been changed.
1819
#' @param ruler_width Integer used to determine the width of the ruler.
20+
#' @keywords internal
1921
communicate_summary <- function(changed, ruler_width) {
2022
cli::cat_rule(width = max(40, ruler_width))
2123
cat("Status\tCount\tLegend \n")
@@ -24,3 +26,10 @@ communicate_summary <- function(changed, ruler_width) {
2426
cli::cat_bullet(bullet = "cross", "\t", sum(is.na(changed)), "\tStyling threw an error.")
2527
cli::cat_rule(width = max(40, ruler_width))
2628
}
29+
30+
stop_insufficient_r_version <- function() {
31+
stop(paste0(
32+
"Can't write tree with R version ", getRversion(),
33+
"since data.tree not available. Needs at least R version 3.2."
34+
), call. = FALSE)
35+
}
File renamed without changes.

R/expr-is.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
#'
33
#' @param pd A parse table.
44
#' @name pd_is
5+
#' @keywords internal
56
NULL
67

78
#' @describeIn pd_is Checks whether `pd` contains an expression wrapped in
89
#' curly brackets.
10+
#' @keywords internal
911
is_curly_expr <- function(pd) {
1012
if (is.null(pd)) return(FALSE)
1113
pd$token[1] == "'{'"
@@ -17,13 +19,15 @@ is_subset_expr <- function(pd) {
1719
}
1820

1921
#' @describeIn pd_is Checks whether `pd` is a function call.
22+
#' @keywords internal
2023
is_function_call <- function(pd) {
2124
if (is.null(pd)) return(FALSE)
2225
if (is.na(pd$token_before[2])) return(FALSE)
2326
pd$token_before[2] == "SYMBOL_FUNCTION_CALL"
2427
}
2528

2629
#' @describeIn pd_is Checks whether `pd` is a function declaration.
30+
#' @keywords internal
2731
is_function_dec <- function(pd) {
2832
if (is.null(pd)) return(FALSE)
2933
pd$token[1] == "FUNCTION"
@@ -42,6 +46,7 @@ is_comment <- function(pd) {
4246
#' @param pd A parse table.
4347
#' @examples
4448
#' style_text("#!/usr/bin/env Rscript")
49+
#' @keywords internal
4550
is_shebang <- function(pd) {
4651
is_first_comment <- is_comment(pd) & (pd$pos_id == 1L)
4752
is_first_comment[is_first_comment] <- grepl(
@@ -61,6 +66,7 @@ is_shebang <- function(pd) {
6166
#' "call(3, 2, c(3:2))"
6267
#' ))
6368
#' @param pd A parse table.
69+
#' @keywords internal
6470
is_code_chunk_header <- function(pd) {
6571
is_comment <- is_comment(pd)
6672
is_comment[is_comment] <- grepl(
@@ -80,6 +86,7 @@ contains_else_expr <- function(pd) {
8086
#' else-if will be visited separately with the visitor. This applies to all
8187
#' conditional statements with more than one alternative.
8288
#' @param pd A parse table
89+
#' @keywords internal
8390
contains_else_expr_that_needs_braces <- function(pd) {
8491
else_idx <- which(pd$token == "ELSE")
8592
if (length(else_idx) > 0) {

R/indent.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#' @param indent_by How many spaces should be added after the token of interest.
66
#' @param token The token the indention should be based on.
77
#' @name update_indention
8+
#' @keywords internal
89
NULL
910

1011
#' @describeIn update_indention Inserts indention based on round, square and
1112
#' curly brackets.
13+
#' @keywords internal
1214
indent_braces <- function(pd, indent_by) {
1315
indent_indices <- compute_indent_indices(
1416
pd,
@@ -21,6 +23,7 @@ indent_braces <- function(pd, indent_by) {
2123

2224
#' @describeIn update_indention Indents *all* tokens after `token` - including
2325
#' the last token.
26+
#' @keywords internal
2427
indent_op <- function(pd,
2528
indent_by,
2629
token = c(
@@ -41,6 +44,7 @@ indent_op <- function(pd,
4144
#' Necessary for consistent indention of the function declaration header.
4245
#' @param pd A parse table.
4346
#' @seealso set_unindention_child update_indention_ref_fun_dec
47+
#' @keywords internal
4448
unindent_fun_dec <- function(pd) {
4549
if (is_function_dec(pd)) {
4650
idx_closing_brace <- which(pd$token %in% "')'")
@@ -55,6 +59,7 @@ unindent_fun_dec <- function(pd) {
5559
#' table are necessarily indented, as `EQ_SUB` and `EQ_FORMALS` can occur
5660
#' multiple times in a parse table.
5761
#' occurs is not indented (see[compute_indent_indices()])
62+
#' @keywords internal
5863
indent_eq_sub <- function(pd,
5964
indent_by,
6065
token = c("EQ_SUB", "EQ_FORMALS")) {
@@ -69,6 +74,7 @@ indent_eq_sub <- function(pd,
6974

7075
#' @describeIn update_indention Same as indent_op, but only indents one token
7176
#' after `token`, not all remaining.
77+
#' @keywords internal
7278
indent_assign <- function(pd, indent_by, token = NULL) {
7379
indent_indices <- compute_indent_indices(pd, token)
7480
pd$indent[indent_indices] <- pd$indent[indent_indices] + indent_by
@@ -77,6 +83,7 @@ indent_assign <- function(pd, indent_by, token = NULL) {
7783

7884
#' @describeIn update_indention Is used to indent for / while / if / if-else
7985
#' statements that do not have curly parenthesis.
86+
#' @keywords internal
8087
indent_without_paren <- function(pd, indent_by = 2) {
8188
pd %>%
8289
indent_without_paren_for_while_fun(indent_by) %>%
@@ -85,6 +92,7 @@ indent_without_paren <- function(pd, indent_by = 2) {
8592

8693
#' @describeIn update_indention Is used to indent for and statements and function
8794
#' definitions without parenthesis.
95+
#' @keywords internal
8896
indent_without_paren_for_while_fun <- function(pd, indent_by) {
8997
nrow <- nrow(pd)
9098
if (!(pd$token[1] %in% c("FOR", "WHILE", "FUNCTION"))) return(pd)
@@ -95,6 +103,7 @@ indent_without_paren_for_while_fun <- function(pd, indent_by) {
95103

96104
#' @describeIn update_indention Is used to indent if and if-else statements.
97105
#' @importFrom rlang seq2
106+
#' @keywords internal
98107
indent_without_paren_if_else <- function(pd, indent_by) {
99108
expr_after_if <- next_non_comment(pd, which(pd$token == "')'")[1])
100109
has_if_without_curly <-
@@ -138,6 +147,7 @@ indent_without_paren_if_else <- function(pd, indent_by) {
138147
#' everything between '(' and the penultimate token would result in the wrong
139148
#' formatting.
140149
#' @importFrom rlang seq2
150+
#' @keywords internal
141151
compute_indent_indices <- function(pd,
142152
token_opening,
143153
token_closing = NULL) {
@@ -166,6 +176,7 @@ compute_indent_indices <- function(pd,
166176
#' @param potential_triggers_pos A vector with indices of the potential trigger
167177
#' tokens in `pd`.
168178
#' @inheritParams needs_indention_one
179+
#' @keywords internal
169180
needs_indention <- function(pd,
170181
potential_triggers_pos,
171182
other_trigger_tokens = NULL) {
@@ -191,6 +202,7 @@ needs_indention <- function(pd,
191202
#' if on the same line as the token corresponding to `potential_trigger`.
192203
#' @return `TRUE` if indention is needed, `FALSE` otherwise.
193204
#' @importFrom rlang seq2
205+
#' @keywords internal
194206
needs_indention_one <- function(pd,
195207
potential_trigger_pos,
196208
other_trigger_tokens) {
@@ -222,6 +234,7 @@ needs_indention_one <- function(pd,
222234
#' of a token is a multi-line token.
223235
#' @param pd A parse table.
224236
#' @importFrom purrr map_lgl
237+
#' @keywords internal
225238
set_multi_line <- function(pd) {
226239
pd$multi_line <- map_lgl(pd$child, pd_is_multi_line)
227240
pd
@@ -234,6 +247,7 @@ set_multi_line <- function(pd) {
234247
#' * it contains a line break.
235248
#' * it has at least one child that is a multi-line expression itself.
236249
#' @param pd A parse table.
250+
#' @keywords internal
237251
pd_is_multi_line <- function(pd) {
238252
any(pd$multi_line, pd$lag_newlines > 0)
239253
}
@@ -250,6 +264,7 @@ pd_is_multi_line <- function(pd) {
250264
#' @param pd A parse table.
251265
#' @return A parse table with synchronized `lag_newlines` and `newlines` columns.
252266
#' @seealso choose_indention
267+
#' @keywords internal
253268
update_newlines <- function(pd) {
254269
npd <- nrow(pd) - 1
255270
pd$newlines[seq_len(npd)] <- pd$lag_newlines[seq_len(npd) + 1]

R/initialize.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#' pd <- styler:::compute_parse_data_nested(string_to_format)
1010
#' styler:::pre_visit(pd, c(default_style_guide_attributes))
1111
#' @export
12+
#' @keywords internal
1213
default_style_guide_attributes <- function(pd_flat) {
1314
init_pd <-
1415
initialize_newlines(pd_flat) %>%
@@ -25,9 +26,11 @@ default_style_guide_attributes <- function(pd_flat) {
2526
#'
2627
#' @name initialize_attributes
2728
#' @inheritParams default_style_guide_attributes
29+
#' @keywords internal
2830
NULL
2931

3032
#' @describeIn initialize_attributes Initializes `newlines` and `lag_newlines`.
33+
#' @keywords internal
3134
initialize_newlines <- function(pd_flat) {
3235
pd_flat$line3 <- lead(pd_flat$line1, default = tail(pd_flat$line2, 1))
3336
pd_flat$newlines <- pd_flat$line3 - pd_flat$line2
@@ -37,6 +40,7 @@ initialize_newlines <- function(pd_flat) {
3740
}
3841

3942
#' @describeIn initialize_attributes Initializes `spaces`.
43+
#' @keywords internal
4044
initialize_spaces <- function(pd_flat) {
4145
pd_flat$col3 <- lead(pd_flat$col1, default = tail(pd_flat$col2, 1) + 1L)
4246
pd_flat$col2_nl <- if_else(pd_flat$newlines > 0L,
@@ -54,6 +58,7 @@ remove_attributes <- function(pd_flat, attributes) {
5458
}
5559

5660
#' @describeIn initialize_attributes Initializes `multi_line`.
61+
#' @keywords internal
5762
initialize_multi_line <- function(pd_flat) {
5863
nrow <- nrow(pd_flat)
5964
pd_flat$multi_line <- if_else(pd_flat$terminal,
@@ -64,12 +69,14 @@ initialize_multi_line <- function(pd_flat) {
6469
}
6570

6671
#' @describeIn initialize_attributes Initializes `indention_ref_ind`.
72+
#' @keywords internal
6773
initialize_indention_ref_pos_id <- function(pd_flat) {
6874
pd_flat$indention_ref_pos_id <- NA
6975
pd_flat
7076
}
7177

7278
#' @describeIn initialize_attributes Initializes `indent`.
79+
#' @keywords internal
7380
initialize_indent <- function(pd_flat) {
7481
if (!("indent" %in% names(pd_flat))) {
7582
pd_flat$indent <- 0
@@ -78,6 +85,7 @@ initialize_indent <- function(pd_flat) {
7885
}
7986

8087
#' @describeIn initialize_attributes validates the parse data.
88+
#' @keywords internal
8189
validate_parse_data <- function(pd_flat) {
8290
if (any(pd_flat$spaces < 0L)) {
8391
stop("Invalid parse data")

0 commit comments

Comments
 (0)