Skip to content

Commit ae7c748

Browse files
Merge branch 'master' into no_reindention_calls
2 parents cd805de + db6d4b1 commit ae7c748

File tree

10 files changed

+52
-23
lines changed

10 files changed

+52
-23
lines changed

DESCRIPTION

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Description:
77
Pretty-prints R code without changing the user's formatting intent.
88
Imports:
99
dplyr,
10-
magrittr,
1110
purrr,
12-
readr,
1311
rlang,
1412
rprojroot,
1513
tibble,

R/nested_to_tree.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ create_tree <- function(text) {
1717
#' @param pd_nested A nested tibble.
1818
#' @return An object of class "Node" and "R6".
1919
#' @examples
20-
#' library("magrittr")
2120
#' code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
22-
#' l1 <- styler:::compute_parse_data_nested(code) %>%
23-
#' styler:::pre_visit(c(styler:::create_filler)) %>%
24-
#' styler:::create_node_from_nested_root()
21+
#' nested_pd <- styler:::compute_parse_data_nested(code)
22+
#' initialized <- styler:::pre_visit(nested_pd, c(styler:::create_filler))
23+
#' styler:::create_node_from_nested_root(initialized)
2524
create_node_from_nested_root <- function(pd_nested) {
2625
n <- data.tree::Node$new("ROOT (token: short_text [lag_newlines/spaces] {id})")
2726
create_node_from_nested(pd_nested, n)

R/styler.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@
44
#' according to a style guide. See the INDEX for more information.
55
#'
66
"_PACKAGE"
7-
if (getRversion() >= "2.15.1") utils::globalVariables(c("."))
7+
if (getRversion() >= "2.15.1") {
8+
utils::globalVariables(c(
9+
".",
10+
"pd", "pd_nested", "pd_flat", "flattened_pd",
11+
"line1", "line2", "col1", "col2",
12+
"terminal", "text", "short",
13+
"spaces", "lag_spaces",
14+
"newlines", "lag_newlines",
15+
NULL
16+
))
17+
}

R/transform.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
#' carefully inspect the changes via a message sent to the console.
1111
transform_files <- function(files, transformers) {
1212
transformer <- make_transformer(transformers)
13-
1413
changed <- utf8::transform_lines_enc(files, transformer)
15-
if (any(changed)) {
14+
if (any(changed, na.rm = TRUE)) {
1615
message("Please review the changes carefully!")
1716
}
1817
invisible(changed)

R/ws.R

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ style_pkg <- function(pkg = ".",
2626
}
2727

2828
prettify_local <- function(transformers) {
29-
r_files <- dir(path = "R", pattern = "[.][rR]$", recursive = TRUE, full.names = TRUE)
29+
r_files <- dir(
30+
path = "R", pattern = "[.][rR]$", recursive = TRUE, full.names = TRUE
31+
)
32+
3033
r_files <- grep("/RcppExports[.]R$", r_files, invert = TRUE, value = TRUE)
31-
test_files <- dir(path = "tests/testthat", pattern = "[.][rR]$", recursive = TRUE, full.names = TRUE)
34+
test_files <- dir(
35+
path = "tests/testthat", pattern = "[.][rR]$",
36+
recursive = TRUE, full.names = TRUE
37+
)
38+
3239
files <- c(r_files, test_files)
3340

3441
transform_files(files, transformers)
@@ -46,6 +53,7 @@ style_text <- function(text,
4653
...,
4754
style = tidyverse_style,
4855
transformers = style(...)) {
56+
4957
transformer <- make_transformer(transformers)
5058
transformer(text)
5159
}
@@ -65,7 +73,9 @@ style_dir <- function(path = ".",
6573
style = tidyverse_style,
6674
transformers = style(...),
6775
recursive = TRUE) {
68-
withr::with_dir(path, prettify_any(transformers, recursive = recursive))
76+
withr::with_dir(
77+
path, prettify_any(transformers, recursive = recursive)
78+
)
6979
}
7080

7181
#' Prettify R code in current working directory
@@ -92,8 +102,10 @@ style_file <- function(path,
92102
...,
93103
style = tidyverse_style,
94104
transformers = style(...)) {
95-
withr::with_dir(dirname(path),
96-
prettify_one(transformers, basename(path)))
105+
withr::with_dir(
106+
dirname(path),
107+
prettify_one(transformers, basename(path))
108+
)
97109
}
98110

99111
#' Prettify one R file

man/create_node_from_nested_root.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
b <- call() {
2+
d
3+
}

tests/testthat/public-api/xyzpackage/.Rbuildignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/testthat/public-api/xyzpackage/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
context("Exception handling")
2+
3+
test_that("style_text returns custom error", {
4+
expect_error(style_text("a <- 3 4"), "unexpected numeric constant")
5+
})
6+
7+
8+
base <- rprojroot::find_testthat_root_file("exception_handling")
9+
test_that("style_file returns custom error", {
10+
expect_warning(
11+
style_file(paste0(base, "/parser-error.R")),
12+
"When processing"
13+
)
14+
})

0 commit comments

Comments
 (0)