Skip to content

Commit

Permalink
empty curly have no spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzwalthert committed Oct 6, 2024
1 parent 08d11e1 commit 9d076fc
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ repos:
)$
- id: roxygenize
additional_dependencies:
- r-lib/pkgapi
- dplyr
- roxygen2
- rlang
Expand Down Expand Up @@ -102,7 +101,7 @@ repos:
)$
- id: pkgdown
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ["--maxkb=200"]
Expand All @@ -120,7 +119,7 @@ repos:
tests/testthat/_snaps/.*|
)$
- repo: https://github.com/lorenzwalthert/gitignore-tidy
rev: 517cddbf1d8514ddaf43159686617ae65895dc99
rev: 0.1.2
hooks:
- id: tidy-gitignore
- repo: local
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else {
warning("Please install r-lib/pkgapi to make sure the file API is kept
up to date"); NULL}))
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Language: en-US
Config/testthat/edition: 3
Config/testthat/parallel: true
Expand Down
7 changes: 6 additions & 1 deletion R/rules-spaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ add_space_after_for_if_while <- function(pd_flat) {

#' @rdname set_line_break_around_curly_curly
#' @keywords internal
set_space_in_curly_curly <- function(pd) {
set_space_in_curly <- function(pd) {
if (is_curly_expr(pd)) {
# curly-curly
after_inner_opening <- pd$token == "'{'" & pd$token_before == "'{'"
before_inner_closing <- lead(pd$token == "'}'" & pd$token_after == "'}'")
is_curly_curly_inner <- any(after_inner_opening, na.rm = TRUE) &&
Expand All @@ -193,6 +194,10 @@ set_space_in_curly_curly <- function(pd) {
pd$spaces[after_outer_opening] <- 0L
pd$spaces[before_outer_closing] <- 0L
}

# empty curly
after_is_empty_curly <- lead(pd$token == "'}'" & pd$token_before == "'{'")
pd$spaces[after_is_empty_curly] <- 0L
}
pd
}
Expand Down
4 changes: 2 additions & 2 deletions R/style-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ tidyverse_style <- function(scope = "tokens",
},
set_space_between_levels = set_space_between_levels,
set_space_between_eq_sub_and_comma = set_space_between_eq_sub_and_comma,
set_space_in_curly_curly = set_space_in_curly_curly
set_space_in_curly = set_space_in_curly
)
}

Expand Down Expand Up @@ -209,7 +209,7 @@ tidyverse_style <- function(scope = "tokens",
start_comments_with_space = "COMMENT",
remove_space_after_unary_pm_nested = c("'+'", "'-'"),
spacing_before_comments = "COMMENT",
set_space_in_curly_curly = c("'{'", "'}'")
set_space_in_curly = c("'{'", "'}'")
),
indention = list(
# indent_braces = c("'('", "'['", "'{'", "')'", "']'", "'}'"),
Expand Down
4 changes: 2 additions & 2 deletions man/set_line_break_around_curly_curly.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/line_breaks_and_other/curly-in.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ test_that(
# comment
expect_equal(1 + 1, 2)
})


while (TRUE) { }

while (TRUE)
{ }
5 changes: 5 additions & 0 deletions tests/testthat/line_breaks_and_other/curly-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ test_that(
expect_equal(1 + 1, 2)
}
)


while (TRUE) {}

while (TRUE) {}

0 comments on commit 9d076fc

Please # to comment.