Skip to content

Commit

Permalink
Merge pull request #1246 from r-lib/rm-space-around-dollar
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Dec 8, 2024
2 parents 2f1cc9b + bf5c500 commit c637dc0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion R/rules-spaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,11 @@ set_space_after_bang_bang <- function(pd_flat) {
pd_flat
}

remove_space_before_dollar <- function(pd_flat) {
remove_space_around_dollar <- function(pd_flat) {
dollar_after <- (pd_flat$token == "'$'") & (pd_flat$lag_newlines == 0L)
dollar_before <- lead(dollar_after, default = FALSE)
pd_flat$spaces[dollar_before] <- 0L
pd_flat$spaces[dollar_after] <- 0L
pd_flat
}

Expand Down
4 changes: 2 additions & 2 deletions R/style-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ tidyverse_style <- function(scope = "tokens",
remove_space_after_opening_paren = remove_space_after_opening_paren,
remove_space_after_excl = remove_space_after_excl,
set_space_after_bang_bang = set_space_after_bang_bang,
remove_space_before_dollar = remove_space_before_dollar,
remove_space_around_dollar = remove_space_around_dollar,
remove_space_after_fun_dec = remove_space_after_fun_dec,
remove_space_around_colons = remove_space_around_colons,
start_comments_with_space = partial(start_comments_with_space,
Expand Down Expand Up @@ -205,7 +205,7 @@ tidyverse_style <- function(scope = "tokens",
# remove_space_after_opening_paren = c("'('", "'['", "LBB"),
remove_space_after_excl = "'!'",
set_space_after_bang_bang = "'!'",
remove_space_before_dollar = "'$'",
remove_space_around_dollar = "'$'",
remove_space_after_fun_dec = "FUNCTION",
remove_space_around_colons = c("':'", "NS_GET_INT", "NS_GET"),
start_comments_with_space = "COMMENT",
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/indention_operators/dollar_R6-in.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x$
add(10) $
x$ add(10)$
add(10) $ add(10) $
add(10)$sum +
3
4 changes: 2 additions & 2 deletions tests/testthat/indention_operators/dollar_R6-out.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x$
add(10)$
x$add(10)$
add(10)$add(10)$
add(10)$sum +
3
5 changes: 5 additions & 0 deletions tests/testthat/spacing/dollar-in.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mtcars $wt

mtcars$ wt

mtcars $ wt
5 changes: 5 additions & 0 deletions tests/testthat/spacing/dollar-out.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mtcars$wt

mtcars$wt

mtcars$wt
7 changes: 7 additions & 0 deletions tests/testthat/test-spacing.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ test_that("spacing around square brackets / braces", {
transformer = style_text, strict = TRUE
), NA)
})

test_that("spacing around dollar", {
expect_warning(test_collection(
"spacing", "dollar",
transformer = style_text, strict = TRUE
), NA)
})

0 comments on commit c637dc0

Please # to comment.