Skip to content

Commit 1020852

Browse files
Merge branch 'master' into patch-1
2 parents c623d55 + 3b94f31 commit 1020852

File tree

396 files changed

+12612
-6188
lines changed

Some content is hidden

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

396 files changed

+12612
-6188
lines changed

.pre-commit-config.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
# All available hooks: https://pre-commit.com/hooks.html
2+
# R specific hooks: https://github.com/lorenzwalthert/precommit
13
repos:
2-
- repo: https://github.com/lorenzwalthert/pre-commit-hooks
3-
rev: v0.0.0.9008
4+
- repo: https://github.com/lorenzwalthert/precommit
5+
rev: v0.0.0.9040
46
hooks:
5-
- id: roxygenize
7+
- id: parsable-R
68
- id: no-browser-statement
9+
# - id: lintr
10+
- id: readme-rmd-rendered
11+
- id: spell-check
12+
- id: style-files
13+
args: [--style_pkg=styler, --style_fun=tidyverse_style]
14+
exclude: 'tests/testthat/.*/*\.R'
15+
- repo: https://github.com/pre-commit/pre-commit-hooks
16+
rev: v2.5.0
17+
hooks:
18+
- id: check-added-large-files
19+
args: ['--maxkb=200']
20+
- id: end-of-file-fixer
21+
exclude: '\.Rd'

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ after_script: R -q -e 'tic::after_script()'
2626
language: r
2727
sudo: false
2828
dist: trusty
29+
cache: packages
2930
latex: false
3031

3132
matrix:
@@ -37,8 +38,9 @@ matrix:
3738
- r: release
3839
env:
3940
- BUILD_PKGDOWN: true
41+
- CODECOV: true
4042
- r: devel
41-
43+
- os: osx
4244
#env
4345
env:
4446
global:

API

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
## Exported functions
44

5-
create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
5+
cache_activate(cache_name = NULL, verbose = TRUE)
6+
cache_clear(cache_name = NULL, ask = TRUE)
7+
cache_deactivate(verbose = TRUE)
8+
cache_info(cache_name = NULL, format = "both")
9+
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)
610
default_style_guide_attributes(pd_flat)
711
specify_math_token_spacing(zero = "'^'", one = c("'+'", "'-'", "'*'", "'/'"))
812
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
9-
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile"), recursive = TRUE, exclude_files = NULL, include_roxygen_examples = TRUE)
10-
style_file(path, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE)
11-
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile"), exclude_files = "R/RcppExports.R", include_roxygen_examples = TRUE)
13+
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile"), recursive = TRUE, exclude_files = NULL, exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, dry = "off")
14+
style_file(path, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, dry = "off")
15+
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile"), exclude_files = "R/RcppExports.R", exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, dry = "off")
1216
style_text(text, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE)
1317
tidyverse_math_token_spacing()
1418
tidyverse_reindention()

DESCRIPTION

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Package: styler
21
Type: Package
2+
Package: styler
33
Title: Non-Invasive Pretty Printing of R Code
4-
Version: 1.1.1.9003
4+
Version: 1.3.2.9000
55
Authors@R:
66
c(person(given = "Kirill",
77
family = "Müller",
@@ -21,6 +21,7 @@ Imports:
2121
cli (>= 1.1.0),
2222
magrittr (>= 1.0.1),
2323
purrr (>= 0.2.3),
24+
R.cache (>= 0.14.0),
2425
rematch2 (>= 2.0.1),
2526
rlang (>= 0.1.1),
2627
rprojroot (>= 1.1),
@@ -30,19 +31,21 @@ Imports:
3031
xfun (>= 0.1)
3132
Suggests:
3233
data.tree (>= 0.1.6),
34+
digest,
3335
dplyr,
3436
here,
3537
knitr,
3638
prettycode,
3739
rmarkdown,
3840
rstudioapi (>= 0.7),
3941
testthat (>= 2.1.0)
40-
VignetteBuilder: knitr
42+
VignetteBuilder:
43+
knitr
4144
Encoding: UTF-8
4245
LazyData: true
4346
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace",
4447
"collate", "pkgapi::api_roclet"))
45-
RoxygenNote: 6.1.1
48+
RoxygenNote: 7.1.0
4649
Collate:
4750
'addins.R'
4851
'communicate.R'
@@ -73,14 +76,18 @@ Collate:
7376
'set-assert-args.R'
7477
'style-guides.R'
7578
'styler.R'
79+
'stylerignore.R'
7680
'testing-mocks.R'
7781
'testing-public-api.R'
82+
'ui-caching.R'
7883
'testing.R'
7984
'token-create.R'
85+
'transform-block.R'
8086
'transform-code.R'
8187
'transform-files.R'
82-
'ui.R'
88+
'ui-styling.R'
8389
'unindent.R'
90+
'utils-cache.R'
8491
'utils-files.R'
8592
'utils-navigate-nest.R'
8693
'utils-strings.R'

NAMESPACE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method(print,vertical)
4+
export(cache_activate)
5+
export(cache_clear)
6+
export(cache_deactivate)
7+
export(cache_info)
48
export(create_style_guide)
59
export(default_style_guide_attributes)
610
export(specify_math_token_spacing)
@@ -31,9 +35,9 @@ importFrom(purrr,map_lgl)
3135
importFrom(purrr,partial)
3236
importFrom(purrr,pmap)
3337
importFrom(purrr,pwalk)
34-
importFrom(purrr,reduce)
3538
importFrom(purrr,when)
3639
importFrom(rlang,abort)
40+
importFrom(rlang,is_empty)
3741
importFrom(rlang,is_installed)
3842
importFrom(rlang,seq2)
3943
importFrom(rlang,warn)

NEWS.md

Lines changed: 133 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,112 @@
1-
# styler 1.1.1.9000
1+
# styler 1.3.2.9000 (Development)
2+
3+
## Major changes
4+
5+
- blank lines in function calls and headers are now removed, for the former only
6+
when there are no comments before or after the blank line (#629, #630, #635).
7+
8+
## Minor chnages and fixes
9+
10+
- overhaul pgkdown site: Add search (#623), group function in Reference (#625).
11+
- always strip trailing spaces and make cache insensitive to it (#626).
12+
- typos in documentation (#618, #614).
13+
14+
15+
# styler 1.3.2
16+
17+
Release upon request by the CRAN team.
18+
19+
## Minor changes and fixes
20+
21+
- Add search and reference sections to pkgdown webpage (#623, #625).
22+
- various fixes to handle special cases for caching and stylerignore and their
23+
interaction (#611, #610, #609, #607, #602, #600).
24+
- also test on macOS (#604).
25+
- skip timing tests on CRAN as requested by CRAN team because they did not pass
26+
on all machines (#603).
27+
28+
# styler 1.3.1
29+
30+
Emergency release. In case multiple expressions are on one line and only
31+
some of them are cached, styler can remove code. To reach this state,
32+
some of the expressions must have been styled previously alone and the cache
33+
must be active. Example:
34+
35+
```
36+
library(styler)
37+
cache_activate()
38+
#> Using cache 1.3.0 at ~/.Rcache/styler/1.3.0.
39+
style_text("1")
40+
#> 1
41+
style_text("1 # comment")
42+
#> # comment
43+
```
44+
45+
This is obviously detrimental. We have added additional tests and fixed the
46+
problem (#593, #595), but we want repeat the warning from `?style_file` that all
47+
style APIs apart from `style_text()` overwrite code and that styler can only
48+
check the AST remains valid with `scope < "tokens"`. So use this if you are
49+
conservative. Or deactivate the cache with `deactivate_cache()` until it has
50+
fully matured.
51+
52+
We thank the people who have contributed to this release:
53+
54+
[&#x0040;ellessenne](https://github.com/ellessenne) and
55+
[&#x0040;renkun-ken](https://github.com/renkun-ken).
56+
57+
# styler 1.3.0
58+
59+
## Breaking changes
60+
61+
* `style_pkg()` and `style_dir()` gain a new argument `exclude_dirs` to exclude
62+
directories from styling, by default `renv` and `packrat`. Note that the
63+
defaults won't change the behavior of `style_pkg()` because it does anyways
64+
does not style these directories and they were set for consistency.
65+
66+
* `style_file()` and friends now strip `./` in file paths returned invisibly,
67+
i.e. `./script.R` becomes `script.R` (#568).
68+
69+
## New features
70+
71+
* ignore certain lines using `# styler: off` and `#styler: on` or custom
72+
markers, see `?stylerignore` (#560).
73+
74+
* styler caches results of styling, so applying styler to code it has styled
75+
before will be instantaneous. This brings large speed boosts in many
76+
situations, e.g. when `style_pkg()` is run but only a few files have changed
77+
since the last styling or when using the [styler pre-commit
78+
hook](https://github.com/lorenzwalthert/precommit). Because styler caches by
79+
expression, you will also get speed boosts in large files with many
80+
expressions when you only change a few of them. See `?caching` for details
81+
(#538, #578).
82+
83+
* `create_style_guide()` gains two arguments `style_guide_name` and
84+
`style_guide_version` that are carried as meta data, in particular to version
85+
third-party style guides and ensure the proper functioning of caching. This
86+
change is completely invisible to users who don't create and distribute their
87+
own style guide like `tidyverse_style()` (#572).
88+
89+
## Minor changes and fixes
90+
91+
* lines are now broken after `+` in `ggplot2` calls for `strict = TRUE` (#569).
92+
93+
* function documentation now contains many more line breaks due to roxygen2
94+
update to version 7.0.1 (#566).
95+
96+
* spaces next to the braces in subsetting expressions `[` and `[[` are now
97+
removed (#580).
98+
99+
* Adapt to changes in the R parser to make styler pass R CMD check again.
100+
(#583).
101+
102+
Thanks to all contributors involved, in particular
103+
[&#x0040;colearendt](https://github.com/colearendt),
104+
[&#x0040;davidski](https://github.com/davidski),
105+
[&#x0040;IndrajeetPatil](https://github.com/IndrajeetPatil),
106+
[&#x0040;pat-s](https://github.com/pat-s), and
107+
[&#x0040;programming-wizard](https://github.com/programming-wizard).
108+
109+
# styler 1.2.0
2110

3111
## Breaking changes
4112

@@ -8,43 +116,53 @@
8116

9117
* `style_file()` and friends do not write content back to a file when styling
10118
does not cause any changes in the file. This means the modification date of
11-
files styled is only changed when the content is changed (#532).
119+
styled files is only changed when the content is changed (#532).
12120

13121
## New features
14122

15-
* Aligned function calls are detected and kept as is if they match the styler
16-
[definition for aligned function calls](https://styler.r-lib.org/articles/detect-alignment.html)
17-
(#537).
123+
* Aligned function calls are detected and remain unchanged if they match the
124+
styler [definition for aligned function
125+
calls](https://styler.r-lib.org/articles/detect-alignment.html) (#537).
18126

19-
* curlyl-curly (`{{`) syntactic sugar introduced with rlang 0.4.0 is now
20-
explicitly handled, as opposed previously where it was just treated as two
21-
consequtive curly braces (#528).
127+
* curly-curly (`{{`) syntactic sugar introduced with rlang 0.4.0 is now
128+
explicitly handled, where previously it was just treated as two consecutive
129+
curly braces (#528).
22130

23131
* `style_pkg()`, `style_dir()` and the Addins can now style `.Rprofile`, and
24132
hidden files are now also styled (#530).
25133

26134
## Minor improvements and fixes
27135

28-
* brace expressions in function calls are formatted in a less compact way. This
29-
improves the formatting of `tryCatch()` in many cases (#543).
30-
31-
* escape characters in roxygen code examples are now correctly escaped (#512).
136+
* Brace expressions in function calls are formatted in a less compact way to
137+
improve readability. Typical use case: `tryCatch()` (#543).
138+
139+
* Arguments in function declarations in a context which is indented multiple
140+
times should now be correct. This typically affects `R6::R6Class()` (#546).
141+
142+
* Escape characters in roxygen code examples are now correctly escaped (#512).
32143

33-
* style selection Addin now preserves line break when the last line selected is
144+
* Special characters such as `\n` in strings are now preserved in text and not
145+
turned into literal values like a line break (#554).
146+
147+
* Style selection Addin now preserves line break when the last line selected is
34148
an entire line (#520).
35149

36-
* style file Addin can now properly handle cancelling (#511).
150+
* Style file Addin can now properly handle cancelling (#511).
37151

38152
* The body of a multi-line function declaration is now indented correctly for
39153
`strict = FALSE` and also wrapped in curly braces for `strict = TRUE` (#536).
40154

41-
* advice for contributors in `CONTRIBUTING.md` was updated (#508).
155+
* Advice for contributors in `CONTRIBUTING.md` was updated (#508).
42156

43157
## Adaption
44158

45159
* styler is now available through the pre-commit hook `style-files` in
46160
https://github.com/lorenzwalthert/pre-commit-hooks.
47161

162+
Thanks to all contributors involved, in particular
163+
164+
[&#x0040;Banana1530](https://github.com/Banana1530), [&#x0040;batpigandme](https://github.com/batpigandme), [&#x0040;cpsievert](https://github.com/cpsievert), [&#x0040;ellessenne](https://github.com/ellessenne), [&#x0040;Emiller88](https://github.com/Emiller88), [&#x0040;hadley](https://github.com/hadley), [&#x0040;IndrajeetPatil](https://github.com/IndrajeetPatil), [&#x0040;krlmlr](https://github.com/krlmlr), [&#x0040;lorenzwalthert](https://github.com/lorenzwalthert), [&#x0040;lwjohnst86](https://github.com/lwjohnst86), [&#x0040;michaelquinn32](https://github.com/michaelquinn32), [&#x0040;mine-cetinkaya-rundel](https://github.com/mine-cetinkaya-rundel), [&#x0040;Moohan](https://github.com/Moohan), [&#x0040;nxskok](https://github.com/nxskok), [&#x0040;oliverbeagley](https://github.com/oliverbeagley), [&#x0040;pat-s](https://github.com/pat-s), [&#x0040;reddy-ia](https://github.com/reddy-ia), and [&#x0040;russHyde](https://github.com/russHyde)
165+
48166
# styler 1.1.1
49167

50168
This is primarily a maintenance release upon the request of the CRAN team
@@ -318,4 +436,3 @@ specify_reindention(
318436
)
319437
initialize_default_attributes(pd_flat)
320438
```
321-

R/addins.R

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ style_active_file <- function() {
6969
}
7070
rstudioapi::modifyRange(
7171
c(1, 1, length(context$contents) + 1, 1),
72-
paste0(ensure_last_is_empty(out), collapse = "\n"),
72+
paste0(ensure_last_n_empty(out), collapse = "\n"),
7373
id = context$id
7474
)
7575
if (Sys.getenv("save_after_styling") == TRUE && context$path != "") {
@@ -120,16 +120,17 @@ set_style_transformers <- function() {
120120
current_style
121121
)
122122
if (!is.null(new_style)) {
123-
parsed_new_style <- with_handlers({
124-
transformers <- eval(parse(text = new_style))
125-
style_text(c("a = 2", "function() {", "NULL", "}"))
126-
},
127-
error = function(e) {
128-
abort(paste0(
129-
"The selected style transformers \"",
130-
new_style, "\" is not valid: ", e$message
131-
))
132-
}
123+
parsed_new_style <- with_handlers(
124+
{
125+
transformers <- eval(parse(text = new_style))
126+
style_text(c("a = 2", "function() {", "NULL", "}"))
127+
},
128+
error = function(e) {
129+
abort(paste0(
130+
"The selected style transformers \"",
131+
new_style, "\" is not valid: ", e$message
132+
))
133+
}
133134
)
134135
options(styler.addins_style_transformer = new_style)
135136
}
@@ -141,7 +142,7 @@ set_style_transformers <- function() {
141142
#'
142143
#' @keywords internal
143144
get_addins_style_transformer_name <- function() {
144-
getOption("styler.addins_style_transformer", default = "styler::tidyverse_style()")
145+
getOption("styler.addins_style_transformer")
145146
}
146147

147148
#' @rdname get_addins_style_transformer_name

0 commit comments

Comments
 (0)