Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid spaces around ^ #308

Merged
merged 4 commits into from Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion API
Expand Up @@ -4,7 +4,7 @@

create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
default_style_guide_attributes(pd_flat)
specify_math_token_spacing(zero = NULL, one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
specify_math_token_spacing(zero = "'^'", one = c("'+'", "'-'", "'*'", "'/'"))
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = "R", recursive = TRUE, exclude_files = NULL)
style_file(path, ..., style = tidyverse_style, transformers = style(...))
Expand Down
6 changes: 4 additions & 2 deletions R/rules-spacing.R
Expand Up @@ -27,9 +27,11 @@ set_space_around_op <- function(pd_flat) {
#' @param zero Character vector of tokens that should be surrounded with zero
#' spaces.
style_space_around_math_token <- function(strict, zero, one, pd_flat) {
# We remove spaces for zero (e.g., around ^ in the tidyverse style guide)
# even for strict = FALSE to be consistent with the : operator
pd_flat %>%
style_space_around_token(strict, zero, 0L) %>%
style_space_around_token(strict, one, 1L)
style_space_around_token(strict = TRUE, zero, 0L) %>%
style_space_around_token(strict = strict, one, 1L)
}

#' Set spacing of token to a certain level
Expand Down
19 changes: 11 additions & 8 deletions R/style_guides.R
Expand Up @@ -289,20 +289,15 @@ character_to_ordered <- function(x, levels, name = substitute(x)) {
#' math_token_spacing = specify_math_token_spacing(zero = "'+'"),
#' strict = TRUE
#' )
#' style_text(
#' "1+1 -3",
#' math_token_spacing = tidyverse_math_token_spacing(),
#' strict = TRUE
#' )
#' @name math_token_spacing
NULL

#' @describeIn math_token_spacing Allows to fully specify the math token
#' spacing.
#' @export
specify_math_token_spacing <-
function(zero = NULL,
one = c("'+'", "'-'", "'*'", "'/'", "'^'")) {
function(zero = "'^'",
one = c("'+'", "'-'", "'*'", "'/'")) {
assert_tokens(c(one, zero))
lst(
one = setdiff(c(math_token, one), zero),
Expand All @@ -317,9 +312,17 @@ specify_math_token_spacing <-
#' style_text(
#' "1+1 -3",
#' math_token_spacing = tidyverse_math_token_spacing(),
#' strict = FALSE
#' )
#' style_text(
#' "1+1 -3",
#' math_token_spacing = tidyverse_math_token_spacing(),
#' strict = TRUE
#' )
#' @export
tidyverse_math_token_spacing <- function() {
specify_math_token_spacing(one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
specify_math_token_spacing(
zero = "'^'",
one = c("'+'", "'-'", "'*'", "'/'")
)
}
6 changes: 3 additions & 3 deletions man/math_token_spacing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/indention_multiple/overall-in.R
Expand Up @@ -17,7 +17,7 @@ a <- function(x) {
c(
list(x + 2),
c(c(
26 ^ 2, # FIXME ^ operator has to be surrounded by one space (or none?!), never multiple
26 ^ 2,
8,
7
)))
Expand Down
79 changes: 39 additions & 40 deletions tests/testthat/indention_multiple/overall-in_tree

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/indention_multiple/overall-out.R
Expand Up @@ -17,7 +17,7 @@ a <- function(x) {
c(
list(x + 2),
c(c(
26 ^ 2, # FIXME ^ operator has to be surrounded by one space (or none?!), never multiple
26^2,
8,
7
))
Expand Down
@@ -1 +1 @@
1 + +1 - 3 / 23 * 3 ^ 4
1 + +1 - 3 / 23 * 3^4
@@ -1 +1 @@
1 + +1 - 3 / 23 * 3 ^ 4
1 + +1 - 3 / 23 * 3^4
2 changes: 1 addition & 1 deletion tests/testthat/strict/non_strict-out.R
Expand Up @@ -65,7 +65,7 @@ test <- function() {
a > b
a * b
a / b
a ^ b
a^b
a & b
a | b
a := b
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/strict/strict-out.R
Expand Up @@ -65,7 +65,7 @@ test <- function() {
a > b
a * b
a / b
a ^ b
a^b
a & b
a | b
a := b
Expand Down
Expand Up @@ -42,7 +42,7 @@ if (TRUE)

if (FALSE)
1 + a * (31 / 2) else
3 ^ k
3^k


if (TRUE)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/token_adding_removing/if_else_strict-out.R
Expand Up @@ -47,7 +47,7 @@ if (TRUE) {
if (FALSE) {
1 + a * (31 / 2)
} else {
3 ^ k
3^k
}


Expand Down