Skip to content

Commit c033b7d

Browse files
committed
Merge branch 'r-0.0-7' into production
2 parents 85a0ab7 + 7d84b5e commit c033b7d

File tree

139 files changed

+3191
-1549
lines changed

Some content is hidden

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

139 files changed

+3191
-1549
lines changed

.gitattributes

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

API

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
get_transformers(flat = FALSE, ...)
66
get_transformers_flat(strict = TRUE, start_comments_with_one_space = FALSE)
7-
get_transformers_nested(strict = TRUE, indent_by = 2, start_comments_with_one_space = FALSE)
7+
get_transformers_nested(scope = "tokens", strict = TRUE, indent_by = 2, start_comments_with_one_space = FALSE)
88
style_dir(path = ".", flat = FALSE, recursive = TRUE, transformers = get_transformers(flat = flat))
99
style_file(path, flat = FALSE, transformers = get_transformers(flat = flat))
1010
style_pkg(pkg = ".", flat = FALSE, transformers = get_transformers(flat = flat))

DESCRIPTION

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
Package: styler
22
Title: Non-invasive Pretty Printing of R code
3-
Version: 0.0-6
3+
Version: 0.0-7
44
Authors@R: person("Kirill", "Müller", role = c("aut", "cre"), email = "[email protected]")
55
Description:
66
Pretty-prints R code without changing the user's formatting intent.
77
Imports:
88
dplyr,
99
magrittr,
10-
pkgload,
1110
purrr,
1211
readr,
1312
rprojroot,
@@ -29,9 +28,28 @@ Remotes:
2928
License: GPL-3
3029
Encoding: UTF-8
3130
LazyData: true
32-
Date: 2017-07-10
31+
Date: 2017-07-27
3332
BugReports: https://github.com/krlmlr/styler/issues
3433
URL: https://github.com/krlmlr/styler, http://krlmlr.github.io/styler
3534
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "pkgapi::api_roclet"))
3635
RoxygenNote: 6.0.1.9000
3736
VignetteBuilder: knitr
37+
Collate:
38+
'get_transformers.R'
39+
'modify_pd.R'
40+
'nested.R'
41+
'nested_to_tree.R'
42+
'parsed.R'
43+
'relevel.R'
44+
'rules-line_break.R'
45+
'rules-other.R'
46+
'rules-replacement.R'
47+
'rules-spacing.R'
48+
'serialize.R'
49+
'serialized_tests.R'
50+
'styler.R'
51+
'transform.R'
52+
'unindent.R'
53+
'utils.R'
54+
'visit.R'
55+
'ws.R'

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ export(style_text)
1010
import(dplyr)
1111
import(tibble)
1212
import(tidyr)
13+
importFrom(purrr,flatten)
1314
importFrom(purrr,flatten_chr)
1415
importFrom(purrr,map)
1516
importFrom(purrr,map2)
17+
importFrom(purrr,map_chr)
1618
importFrom(purrr,map_lgl)
1719
importFrom(purrr,partial)
1820
importFrom(purrr,pmap)

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## styler 0.0-7 (2017-07-27)
2+
3+
- curly braces don't move a line up if previous token is comment.
4+
- wrap parse + transform + serialize in new function.
5+
- Speedup of nested styler functions by ~ 4x.
6+
- Use multi line instead of line1 / line2 for indention and unindention.
7+
- Indent multiple.
8+
- add tidyverse rules (indention not yet working properly).
9+
- Refactoring and add token before and afterwards to parse table.
10+
- Implement post visitor instead of complicated move_up child.
11+
12+
113
## styler 0.0-6 (2017-07-10)
214

315
* Tidy up README (#43).

R/get_transformers.R

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ get_transformers <- function(flat = FALSE, ...) {
1414
get_transformers_nested(...)
1515
}
1616
}
17+
1718
#' Get the transformer functions for flat styling
1819
#'
1920
#' @param strict A logical value indicating whether a set of strict
@@ -36,7 +37,6 @@ get_transformers_flat <- function(strict = TRUE,
3637
if (strict) set_space_around_op else add_space_around_op,
3738
if (strict) set_space_after_comma else add_space_after_comma,
3839
remove_space_before_comma,
39-
remove_space_after_unary_pm,
4040
remove_space_after_opening_paren,
4141
partial(start_comments_with_space,
4242
force_one = start_comments_with_one_space),
@@ -47,23 +47,90 @@ get_transformers_flat <- function(strict = TRUE,
4747
#'
4848
#' Similar to [get_transformers_flat()], but additionally, returns some
4949
#' functions needed due the fact that styling is done in a nested way.
50+
#' @param scope The extent of manipulation. Can range from "none" (least
51+
#' invasive) to "token" (most invasive). See 'Details'. This argument is a
52+
#' vector of length one.
5053
#' @param indent_by How many spaces of indention should be inserted after
5154
#' operators such as '('.
5255
#' @inheritParams get_transformers_flat
56+
#' @details The following options for `scope` are available.
57+
#'
58+
#' * "none": Performs no transformation at all.
59+
#' * "spaces": Manipulates spacing between token on the same line.
60+
#' * "line_breaks": In addition to "spaces", this option also manipulates
61+
#' line breaks.
62+
#' * "tokens": In addition to "line_breaks", this option also manipulates
63+
#' tokens.
64+
#'
65+
#' As it becomes clear from this description, more invasive operations can only
66+
#' be performed if all less invasive operations are performed too.
5367
#' @family obtain transformers
5468
#' @importFrom purrr partial
5569
#' @export
56-
get_transformers_nested <- function(strict = TRUE,
57-
indent_by = 2,
58-
start_comments_with_one_space = FALSE) {
59-
c(create_filler,
60-
partial(indent_round, indent_by = indent_by),
61-
partial(indent_curly, indent_by = indent_by),
62-
partial(indent_op, indent_by = indent_by),
63-
strip_eol_spaces,
64-
get_transformers_flat(strict, start_comments_with_one_space),
65-
remove_space_after_unary_pm_nested,
66-
set_space_before_comments,
67-
set_space_between_levels
70+
get_transformers_nested <- function(
71+
scope = "tokens",
72+
strict = TRUE,
73+
indent_by = 2,
74+
start_comments_with_one_space = FALSE) {
75+
76+
lvls_scope <- c("none", "spaces", "line_breaks", "tokens")
77+
78+
scope <- character_to_ordered(scope, lvls_scope)
79+
80+
space_manipulators <- if (scope >= lvls_scope[2])
81+
c(
82+
partial(indent_round, indent_by = indent_by),
83+
partial(indent_curly, indent_by = indent_by),
84+
partial(indent_op, indent_by = indent_by),
85+
partial(indent_without_paren, indent_by = indent_by),
86+
partial(indent_assign, indent_by = indent_by),
87+
get_transformers_flat(strict, start_comments_with_one_space),
88+
remove_space_after_unary_pm_nested,
89+
set_space_before_comments,
90+
set_space_between_levels
91+
)
92+
93+
line_break_manipulators <- if (scope >= lvls_scope[3])
94+
c(
95+
remove_line_break_before_curly_opening,
96+
remove_line_break_before_round_closing,
97+
add_line_break_afer_curly_opening,
98+
add_line_break_before_curly_closing,
99+
add_line_break_after_pipe
100+
)
101+
102+
token_manipulators <- if (scope >= lvls_scope[4])
103+
c(
104+
force_assignment_op,
105+
resolve_semicolon,
106+
add_brackets_in_pipe
68107
)
108+
109+
110+
list(
111+
filler = create_filler,
112+
line_break = line_break_manipulators,
113+
space = space_manipulators,
114+
token = token_manipulators,
115+
eol = strip_eol_spaces,
116+
NULL
117+
)
69118
}
119+
120+
121+
#' Convert a character vector to an ordered factor
122+
#'
123+
#' Convert a vector to an ordered factor but stop if any of the values in
124+
#' `x` does not match the predefined levels in `levels.`
125+
#' @param x A character vector.
126+
#' @param levels A vector with levels.
127+
#' @param name The name of the character vector to be dispayed if the
128+
#' construction of the factor fails.
129+
character_to_ordered <- function(x, levels, name = substitute(x)) {
130+
if (!all((x %in% levels))) {
131+
stop("all values in ", name, " must be one of the following: ",
132+
paste(levels, collapse = ", "))
133+
}
134+
factor(x, levels = levels, ordered = TRUE)
135+
}
136+

0 commit comments

Comments
 (0)