Skip to content

Commit 3ef57c2

Browse files
Merge 816a718 into 9305b62
2 parents 9305b62 + 816a718 commit 3ef57c2

File tree

69 files changed

+608
-152
lines changed

Some content is hidden

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

69 files changed

+608
-152
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tests/testthat/**/*_tree linguist-generated=true
1+
tests/testthat/**/*_tree linguist-generated=true

.github/workflows/R-CMD-check.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ jobs:
2727
matrix:
2828
config:
2929
- {os: macOS-latest, r: 'release'}
30+
- {os: windows-latest, r: 'devel'}
3031
- {os: windows-latest, r: 'release'}
31-
- {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"}
32-
- {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
32+
- {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"}
33+
- {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.0.0 (ubuntu-18.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
3334
- {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
3435
- {os: ubuntu-18.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
3536
- {os: ubuntu-18.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}

.github/workflows/check-full.yaml

Whitespace-only changes.

.github/workflows/pkgdown.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: master
3+
branches: main
44

55
name: pkgdown
66

.github/workflows/test-coverage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
on:
22
push:
33
branches:
4-
- master
4+
- main
55
pull_request:
66
branches:
7-
- master
7+
- main
88

99
name: test-coverage
1010

.pre-commit-config.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ default_stages: [commit]
44

55
repos:
66
- repo: https://github.com/lorenzwalthert/precommit
7-
rev: v0.1.3.9014
7+
rev: v0.1.3.9139
88
hooks:
99
- id: style-files
1010
args: [--style_pkg=styler, --style_fun=tidyverse_style]
1111
exclude: >
1212
(?x)^(
13-
tests/testthat/.*/.*\.R(md)?|
13+
tests/testthat/.*/.*\.R(md|nw)?|
1414
vignettes/customizing_styler\.Rmd|
1515
tests/testthat/public-api/xyzfile-rnw/random4\.Rnw|
16+
vignettes/detect-alignment\.Rmd|
17+
tests/testmanual/addins/.*invalid.*|
18+
tests/testmanual/addins/r-valid\.R|
1619
)$
1720
- id: roxygenize
21+
additional_dependencies:
22+
- r-lib/pkgapi
1823
- id: use-tidy-description
1924
- id: spell-check
2025
exclude: >
@@ -49,7 +54,8 @@ repos:
4954
tests/testthat/public-api/xyzaddin/addin_region-.*|
5055
tests/testmanual/addins/r-invalid\.R|
5156
tests/testthat/escaping/basic-escape-out\.R|
52-
tests/testthat/indention_operators/base_pipe_and_assignment-.*|
57+
tests/testthat/indention_operators/.*pipe.*|
58+
tests/testthat/line_breaks_and_other/.*pipe.*|
5359
tests/testthat/exception_handling/parser-error.R|
5460
)$
5561
- id: no-browser-statement
@@ -58,14 +64,15 @@ repos:
5864
tests/testthat/public-api/xyzaddin/addin_region-.*|
5965
tests/testmanual/addins/r-invalid\.R|
6066
tests/testthat/escaping/basic-escape-out\.R|
61-
tests/testthat/indention_operators/base_pipe_and_assignment-.*|
67+
tests/testthat/indention_operators/.*pipe.*|
68+
tests/testthat/line_breaks_and_other/.*pipe.*|
6269
tests/testthat/exception_handling/parser-error.R|
6370
)$
6471
- id: deps-in-desc
6572
exclude: >
6673
(?x)^(
6774
touchstone/.*|
68-
tests/testmanual/addins/r-invalid\.R|
75+
tests/testmanual/addins/.*invalid.*|
6976
tests/testthat/escaping/basic-escape-out\.R|
7077
tests/testthat/rnw/011-conditional-eval-out\.Rnw|
7178
tests/testthat/.*\.R(md)?
@@ -76,7 +83,13 @@ repos:
7683
- id: check-added-large-files
7784
args: ['--maxkb=200']
7885
- id: end-of-file-fixer
79-
exclude: '\.Rd'
86+
exclude: >
87+
(?x)^(
88+
\.Rd|
89+
tests/testthat/exception_handling/empty_file\.R|
90+
tests/testthat/parse_comments/eol_eof_spaces-.*|
91+
tests/testthat/reference-objects/.*|
92+
)$
8093
- repo: local
8194
hooks:
8295
- id: forbid-to-commit

DESCRIPTION

Lines changed: 4 additions & 4 deletions
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.6.2
4+
Version: 1.6.2.9000
55
Authors@R:
66
c(person(given = "Kirill",
77
family = "Müller",
@@ -16,8 +16,9 @@ Description: Pretty-prints R code without changing the user's formatting
1616
License: MIT + file LICENSE
1717
URL: https://github.com/r-lib/styler, https://styler.r-lib.org
1818
BugReports: https://github.com/r-lib/styler/issues
19+
Depends:
20+
R (>= 3.4.0)
1921
Imports:
20-
backports (>= 1.1.0),
2122
cli (>= 1.1.0),
2223
glue,
2324
magrittr (>= 2.0.0),
@@ -29,7 +30,6 @@ Imports:
2930
tibble (>= 1.4.2),
3031
tools,
3132
withr (>= 1.0.0),
32-
xfun (>= 0.1)
3333
Suggests:
3434
data.tree (>= 0.1.6),
3535
digest,
@@ -46,7 +46,7 @@ VignetteBuilder:
4646
Encoding: UTF-8
4747
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate",
4848
"pkgapi::api_roclet"))
49-
RoxygenNote: 7.1.1.9001
49+
RoxygenNote: 7.1.2
5050
Collate:
5151
'addins.R'
5252
'communicate.R'

NEWS.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
# styler 1.2
1+
# styler 1.6.2.9000 (Development version)
2+
3+
* Alignment detection respects stylerignore (#850).
4+
* Add vignette on distributing style guide (#846, #861).
5+
* Enable pre-commit.ci (#843).
6+
* new R option `styler.cache_root` (defaulting to `"styler"`) that determines
7+
the sub-directory under the {R.cache} cache directory that {styler} uses. Non-
8+
default caches won't be cleaned up by {styler}. We suggest `"styler-perm"`
9+
(also used by {precommit}).
10+
* rename default branch to main (#859).
11+
* Fix argument name `filetype` in Example for `style_dir()` (#855).
12+
* ensure a trailing blank line also if the input is cached (#867).
13+
* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which
14+
allowed to remove the dependency at {backports} and some exception handling.
15+
* Remove dependency on {xfun} (#866).
16+
* use bootstrap 5 with {pkgdown} 2.0
17+
18+
# styler 1.6.2
219

320
* clean up cache files older than one week (#842).
421

R/addins.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#' Helper functions for styling via RStudio Addins.
44
#' @section Addins:
55
#' - Set style: Select the style transformers to use. For flexibility, the user
6-
#' input is passed to the `transformers` argument, not the `style` argument, so
7-
#' entering `styler::tidyverse_style(scope = "spaces")` in the Addin is
6+
#' input is passed to the `transformers` argument, not the `style` argument,
7+
#' so entering `styler::tidyverse_style(scope = "spaces")` in the Addin is
88
#' equivalent to `styler::style_text("1+1", scope = "spaces")` and
99
#' `styler::style_text("1+1", transformers = styler::tidyverse_style(scope = "spaces"))`
1010
#' if the text to style is `1+1`. The style transformers are memorized

R/communicate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @inheritParams can_verify_roundtrip
88
#' @keywords internal
99
communicate_warning <- function(changed, transformers) {
10-
if (any(changed, na.rm = TRUE) &&
10+
if (any(changed, na.rm = TRUE) &&
1111
!can_verify_roundtrip(transformers) &&
1212
!getOption("styler.quiet", FALSE)
1313
) {

R/detect-alignment.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ token_is_on_aligned_line <- function(pd_flat) {
4949
pd_flat$lag_newlines <- pd_flat$pos_id <- NULL
5050
pd_flat$.lag_spaces <- lag(pd_flat$spaces)
5151
pd_by_line <- split(pd_flat, line_idx)
52+
pd_by_line[purrr::map_lgl(pd_by_line, ~ any(.x$stylerignore))] <- NULL
53+
if (length(pd_by_line) < 1) {
54+
return(TRUE)
55+
}
5256
last_line_is_closing_brace_only <- nrow(last(pd_by_line)) == 1
5357
relevant_idx <- seq2(2, ifelse(last_line_is_closing_brace_only,
5458
length(pd_by_line) - 1,
@@ -86,7 +90,11 @@ token_is_on_aligned_line <- function(pd_flat) {
8690
}
8791

8892
pd_by_line <- alignment_drop_comments(pd_by_line) %>%
89-
alignment_ensure_no_closing_brace(last_line_is_closing_brace_only) %>%
93+
alignment_ensure_no_closing_brace(last_line_is_closing_brace_only)
94+
if (length(pd_by_line) < 1) {
95+
return(TRUE)
96+
}
97+
pd_by_line <- pd_by_line %>%
9098
alignment_ensure_trailing_comma()
9199
# now, pd only contains arguments separated by values, ideal for iterating
92100
# over columns.

R/io.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ transform_utf8_one <- function(path, fun, dry) {
4242
} else if (dry == "on") {
4343
# don't do anything
4444
} else if (dry == "off") {
45-
xfun::write_utf8(new, path)
45+
write_utf8(new, path)
4646
} else {
4747
# not implemented
4848
}
@@ -114,3 +114,10 @@ read_utf8_bare <- function(con, warn = TRUE) {
114114
invalid_utf8 <- function(x) {
115115
which(!is.na(x) & is.na(iconv(x, "UTF-8", "UTF-8")))
116116
}
117+
118+
#' Drop-in replacement for `xfun::write_utf8()`
119+
#' @keywords internal
120+
write_utf8 <- function(text, con, ...) {
121+
withr::local_options(encoding = "native.enc")
122+
writeLines(enc2utf8(text), con, ..., useBytes = TRUE)
123+
}

R/parse.R

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ add_id_and_short <- function(pd) {
127127
#' @importFrom magrittr or
128128
#' @keywords internal
129129
ensure_correct_txt <- function(pd, text) {
130-
ensure_valid_pd(pd)
131130
is_problematic_text <- or(
132131
is_insufficiently_parsed_string(pd),
133132
is_insufficiently_parsed_number(pd)
@@ -173,30 +172,6 @@ ensure_correct_txt <- function(pd, text) {
173172
arrange_pos_id()
174173
}
175174

176-
#' Ensure that the parse data is valid
177-
#'
178-
#' Test whether all non-terminals have at least one child and throw an error
179-
#' otherwise. As this is check is rather expensive, it is only
180-
#' carried out for configurations we have good reasons to expect problems.
181-
#' @param pd A parse table.
182-
#' @importFrom rlang abort
183-
#' @keywords internal
184-
ensure_valid_pd <- function(pd) {
185-
if (getRversion() < "3.2") {
186-
non_terminals <- pd %>%
187-
filter(terminal == FALSE)
188-
valid_pd <- non_terminals$id %>%
189-
map_lgl(~ .x %in% pd$parent) %>%
190-
all()
191-
if (!valid_pd) {
192-
abort(paste(
193-
"The parse data is not valid and the problem is most likely related",
194-
"to the parser in base R. Please install R >= 3.2 and try again."
195-
))
196-
}
197-
}
198-
TRUE
199-
}
200175

201176
#' Identify strings that were not fully parsed
202177
#'

R/roxygen-examples-find.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ identify_start_to_stop_of_roxygen_examples_from_text <- function(text) {
2222
}
2323

2424
identify_start_to_stop_of_roxygen_examples <- function(path) {
25-
content <- xfun::read_utf8(path)
25+
content <- read_utf8_bare(path)
2626
identify_start_to_stop_of_roxygen_examples_from_text(content)
2727
}
2828

R/rules-line-breaks.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
#' # brace expressions go on new line if part of a pipe, in function call...
4242
#' c(
4343
#' data %>%
44-
#' filter(bar) %>% {
44+
#' filter(bar) %>%
45+
#' {
4546
#' cor(.$col1, .$col2, use = "complete.obs")
4647
#' }
4748
#' )

R/testing.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ transform_and_check <- function(in_item, out_item,
110110
write_tree = NA,
111111
out_tree = "_tree", ...) {
112112
write_tree <- set_arg_write_tree(write_tree)
113-
read_in <- xfun::read_utf8(in_item)
113+
read_in <- read_utf8_bare(in_item)
114114
if (write_tree) {
115115
create_tree(read_in) %>%
116116
write.table(out_tree,
@@ -337,6 +337,7 @@ activate_testthat_cache <- purrr::partial(cache_activate, "testthat")
337337
#' @param .local_envir The environment to use for scoping.
338338
#' @details
339339
#' * make styler quiet.
340+
#' @keywords internal
340341
local_test_setup <- function(cache = FALSE,
341342
.local_envir = parent.frame()) {
342343
current_cache <- cache_info(format = "tabular")

R/transform-files.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ make_transformer <- function(transformers,
8888
assert_transformers(transformers)
8989

9090
function(text) {
91-
text <- trimws(text, which = "right")
91+
text <- ensure_last_n_empty(trimws(text, which = "right"), n = 0L)
9292
should_use_cache <- cache_is_activated()
9393

9494
if (should_use_cache) {
@@ -232,7 +232,7 @@ parse_transform_serialize_r <- function(text,
232232
return("")
233233
}
234234
transformers <- transformers_drop(
235-
if (getRversion() < 3.4) text else pd_nested$text[!pd_nested$is_cached],
235+
pd_nested$text[!pd_nested$is_cached],
236236
transformers
237237
)
238238

R/ui-styling.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ style_text <- function(text,
229229
#' @family stylers
230230
#' @examples
231231
#' \dontrun{
232-
#' style_dir("path/to/dir", file_type = c("rmd", ".R"))
232+
#' style_dir("path/to/dir", filetype = c("rmd", ".R"))
233233
#'
234234
#' # the following is identical (because of ... and defaults)
235235
#' # but the first is most convenient:
@@ -312,7 +312,7 @@ prettify_any <- function(transformers,
312312
#' @inheritSection style_pkg Round trip validation
313313
#' @examples
314314
#' file <- tempfile("styler", fileext = ".R")
315-
#' xfun::write_utf8("1++1", file)
315+
#' writeLines("1++1", file)
316316
#'
317317
#' # the following is identical (because of ... and defaults),
318318
#' # but the first is most convenient:
@@ -325,7 +325,7 @@ prettify_any <- function(transformers,
325325
#' # name levels explicitly to not style less invasive levels
326326
#' style_file(file, scope = I(c("tokens", "spaces")), strict = TRUE)
327327
#'
328-
#' xfun::read_utf8(file)
328+
#' readLines(file)
329329
#' unlink(file)
330330
#' @family stylers
331331
#' @export

0 commit comments

Comments
 (0)