Skip to content

Commit 988a9ac

Browse files
Merge e4866e5 into 9305b62
2 parents 9305b62 + e4866e5 commit 988a9ac

File tree

80 files changed

+798
-176
lines changed

Some content is hidden

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

80 files changed

+798
-176
lines changed

.Rbuildignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ revdep
2121
^touchstone$
2222
^\.github$
2323
^LICENSE\.md$
24-
^inst/hooks/$
24+
^inst/hooks/.*$
2525
^inst/WORDLIST$
26+
^.*-in_tree$
27+
^vignettes/gsoc_proposal$

.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/pre-commit.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: pre-commit
2+
on:
3+
push:
4+
branches-ignore:
5+
- 'master'
6+
- 'main'
7+
pull_request:
8+
types: [opened, synchronize, reopened, ready_for_review]
9+
10+
jobs:
11+
pre-commit:
12+
runs-on: ubuntu-18.04
13+
if: >-
14+
!contains(github.event.head_commit.message, 'ci skip') &&
15+
(
16+
startsWith(github.ref, 'refs/heads') ||
17+
github.event.pull_request.draft == false
18+
)
19+
steps:
20+
- name: Cancel Previous Runs
21+
uses: styfle/[email protected]
22+
with:
23+
access_token: ${{ github.token }}
24+
- uses: actions/checkout@v2
25+
with:
26+
fetch-depth: 0
27+
- name: Install system dependencies
28+
if: runner.os == 'Linux'
29+
run: |
30+
# your system installation code here
31+
# sudo apt-get install -y libcurl4-openssl-dev
32+
- name: Set up Python
33+
uses: actions/setup-python@v2
34+
with:
35+
python-version: "3.8"
36+
architecture: "x64"
37+
- name: Run pre-commit
38+
uses: pre-commit/[email protected]
39+
- name: Commit files
40+
if: failure() && startsWith(github.ref, 'refs/heads')
41+
run: |
42+
if [[ `git status --porcelain --untracked-files=no` ]]; then
43+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
44+
git config --local user.name "github-actions[bot]"
45+
git checkout -- .github/workflows
46+
git commit -m "pre-commit" -a
47+
fi
48+
- name: Push changes
49+
if: failure() && startsWith(github.ref, 'refs/heads')
50+
uses: ad-m/github-push-action@master
51+
with:
52+
github_token: ${{ secrets.GITHUB_TOKEN }}
53+
branch: ${{ github.ref }}
54+
env:
55+
RENV_CONFIG_CACHE_ENABLED: FALSE

.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: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
1-
# styler 1.2
1+
# styler 1.6.2.9000 (Development version)
2+
3+
* Piped function without brackets `substitute(x %>% y)` don't get `()` added
4+
anymore, as this can change outcome of the code (#876).
5+
* Alignment detection respects stylerignore (#850).
6+
* Add vignette on distributing style guide (#846, #861).
7+
* Enable pre-commit.ci (#843).
8+
* new R option `styler.cache_root` (defaulting to `"styler"`) that determines
9+
the sub-directory under the {R.cache} cache directory that {styler} uses. Non-
10+
default caches won't be cleaned up by {styler}. We suggest `"styler-perm"`
11+
(also used by {precommit}).
12+
* rename default branch to main (#859).
13+
* Fix argument name `filetype` in Example for `style_dir()` (#855).
14+
* ensure a trailing blank line also if the input is cached (#867).
15+
* Bump minimal R requirement to 3.4 in line with the [tidyverse](https://www.tidyverse.org/blog/2019/04/r-version-support/), which
16+
allowed to remove the dependency at {backports} and some exception handling.
17+
* Remove dependency on {xfun} (#866).
18+
* use pre-commit via GitHub Actions (#872).
19+
20+
* stylerignore markers are now interpreted as regular expressions instead of
21+
comments that must match exactly. This allows to specify multiple markers in
22+
one regular expression for `styler.ignore_start` and `styler.ignore_stop`,
23+
e.g. to use markers for lintr and styler on the same line, you can use
24+
`options(styler.ignore_start = "nolint start|styler: off"`:
25+
26+
```r
27+
# nolint start, styler: off
28+
1 +1
29+
# nolint end
30+
# styler: on
31+
```
32+
As a consequence of this approach, the defaults for `styler.ignore_start` and
33+
`styler.ignore_stop` omit the `#` (#849).
34+
35+
* the built package size has been reduced by ~50% by listing `*-in_tree` files
36+
in `.Rbuildignore` (#879).
37+
38+
# styler 1.6.2
239

340
* clean up cache files older than one week (#842).
441

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/nest.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,20 @@ find_pos_id_to_keep <- function(pd) {
159159
#' [detected by styler](https://styler.r-lib.org/articles/detect-alignment.html),
160160
#' making stylerignore redundant. See a few illustrative examples below.
161161
#' @details
162-
#' Styling is on by default when you run styler.
162+
#' Styling is on for all lines by default when you run styler.
163163
#'
164164
#' - To mark the start of a sequence where you want to turn styling off, use
165165
#' `# styler: off`.
166166
#' - To mark the end of this sequence, put `# styler: on` in your code. After
167167
#' that line, styler will again format your code.
168168
#' - To ignore an inline statement (i.e. just one line), place `# styler: off`
169-
#' at the end of the line. Note that inline statements cannot contain other
170-
#' comments apart from the marker, i.e. a line like
171-
#' `1 # comment # styler: off` won't be ignored.
172-
#'
169+
#' at the end of the line.
173170
#' To use something else as start and stop markers, set the R options
174171
#' `styler.ignore_start` and
175-
#' `styler.ignore_stop` using [options()]. If you want these
176-
#' settings to persist over multiple R sessions, consider setting them in your
177-
#' R profile, e.g. with `usethis::edit_rprofile()`.
172+
#' `styler.ignore_stop` using [options()]. For styler version > 1.6.2, the
173+
#' option supports character vectors longer than one and the marker are not
174+
#' exactly matched, but using a regular expression, which means you can have
175+
#' multiple marker on one line, e.g. `# nolint start styler: off`.
178176
#' @name stylerignore
179177
#' @examples
180178
#' # as long as the order of the markers is correct, the lines are ignored.

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

0 commit comments

Comments
 (0)