Skip to content

Commit b591a12

Browse files
Merge branch 'master' into indent-eq-formal
merge with master containing tests already by using the ours merge strategy (i.e. prefer indent-eq-formals whenever there is a conflict)
2 parents 6880d75 + 6ea9c77 commit b591a12

17 files changed

+78
-74
lines changed

API

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

55
create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
66
default_style_guide_attributes(pd_flat)
7-
specify_math_token_spacing(zero = NULL, one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
7+
specify_math_token_spacing(zero = "'^'", one = c("'+'", "'-'", "'*'", "'/'"))
88
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
99
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = "R", recursive = TRUE, exclude_files = NULL)
1010
style_file(path, ..., style = tidyverse_style, transformers = style(...))

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Imports:
1414
rematch2,
1515
rlang,
1616
rprojroot,
17-
tibble,
17+
tibble (>= 1.4.2),
1818
withr
1919
Suggests:
2020
data.tree,

R/rules-spacing.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ set_space_around_op <- function(pd_flat) {
2727
#' @param zero Character vector of tokens that should be surrounded with zero
2828
#' spaces.
2929
style_space_around_math_token <- function(strict, zero, one, pd_flat) {
30+
# We remove spaces for zero (e.g., around ^ in the tidyverse style guide)
31+
# even for strict = FALSE to be consistent with the : operator
3032
pd_flat %>%
31-
style_space_around_token(strict, zero, 0L) %>%
32-
style_space_around_token(strict, one, 1L)
33+
style_space_around_token(strict = TRUE, zero, 0L) %>%
34+
style_space_around_token(strict = strict, one, 1L)
3335
}
3436

3537
#' Set spacing of token to a certain level
@@ -240,7 +242,7 @@ set_space_after_bang_bang <- function(pd_flat) {
240242
(pd_flat$newlines == 0L) &
241243
(pd_flat$token_before == "'!'")
242244

243-
pd_flat$spaces[last_bang] <- 1L
245+
pd_flat$spaces[last_bang] <- 0L
244246
pd_flat
245247
}
246248

R/style_guides.R

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,15 @@ character_to_ordered <- function(x, levels, name = substitute(x)) {
290290
#' math_token_spacing = specify_math_token_spacing(zero = "'+'"),
291291
#' strict = TRUE
292292
#' )
293-
#' style_text(
294-
#' "1+1 -3",
295-
#' math_token_spacing = tidyverse_math_token_spacing(),
296-
#' strict = TRUE
297-
#' )
298293
#' @name math_token_spacing
299294
NULL
300295

301296
#' @describeIn math_token_spacing Allows to fully specify the math token
302297
#' spacing.
303298
#' @export
304299
specify_math_token_spacing <-
305-
function(zero = NULL,
306-
one = c("'+'", "'-'", "'*'", "'/'", "'^'")) {
300+
function(zero = "'^'",
301+
one = c("'+'", "'-'", "'*'", "'/'")) {
307302
assert_tokens(c(one, zero))
308303
lst(
309304
one = setdiff(c(math_token, one), zero),
@@ -318,9 +313,17 @@ specify_math_token_spacing <-
318313
#' style_text(
319314
#' "1+1 -3",
320315
#' math_token_spacing = tidyverse_math_token_spacing(),
316+
#' strict = FALSE
317+
#' )
318+
#' style_text(
319+
#' "1+1 -3",
320+
#' math_token_spacing = tidyverse_math_token_spacing(),
321321
#' strict = TRUE
322322
#' )
323323
#' @export
324324
tidyverse_math_token_spacing <- function() {
325-
specify_math_token_spacing(one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
325+
specify_math_token_spacing(
326+
zero = "'^'",
327+
one = c("'+'", "'-'", "'*'", "'/'")
328+
)
326329
}

man/math_token_spacing.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/indention_multiple/overall-in.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ a <- function(x) {
1717
c(
1818
list(x + 2),
1919
c(c(
20-
26 ^ 2, # FIXME ^ operator has to be surrounded by one space (or none?!), never multiple
20+
26 ^ 2,
2121
8,
2222
7
2323
)))

tests/testthat/indention_multiple/overall-in_tree

Lines changed: 39 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/indention_multiple/overall-out.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ a <- function(x) {
1717
c(
1818
list(x + 2),
1919
c(c(
20-
26 ^ 2, # FIXME ^ operator has to be surrounded by one space (or none?!), never multiple
20+
26^2,
2121
8,
2222
7
2323
))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1 + +1 - 3 / 23 * 3 ^ 4
1+
1 + +1 - 3 / 23 * 3^4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1 + +1 - 3 / 23 * 3 ^ 4
1+
1 + +1 - 3 / 23 * 3^4

0 commit comments

Comments
 (0)