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

Remove blank lines after opening and before closing braces #1195

Merged
merged 25 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1057135
initial work on remove blank lines before and after braces
IndrajeetPatil May 1, 2024
47b7da7
pre-commit
github-actions[bot] May 1, 2024
0fcbc96
add tests for LBB
IndrajeetPatil May 1, 2024
9464800
more tests
IndrajeetPatil May 1, 2024
280b272
bandaid
IndrajeetPatil May 1, 2024
b687296
Merge branch 'main' into f1032-remove-blank-lines-after-and-before-pa…
IndrajeetPatil May 6, 2024
8f4bda9
include tests with comments; remove strict param
IndrajeetPatil May 7, 2024
304792d
Merge branch 'main' into f1032-remove-blank-lines-after-and-before-pa…
IndrajeetPatil May 10, 2024
2df29fb
create new transformers for removing empty lines
IndrajeetPatil May 11, 2024
e0e2ed4
better naming
IndrajeetPatil May 11, 2024
226615d
add tests with pipes
IndrajeetPatil May 11, 2024
0d67987
also add tests for roxygen comments
IndrajeetPatil May 11, 2024
1f60831
Merge branch 'main' into f1032-remove-blank-lines-after-and-before-pa…
IndrajeetPatil May 11, 2024
d1fb41e
run on R-release on Ubuntu
IndrajeetPatil May 11, 2024
a7056be
remove non-existing token
IndrajeetPatil May 11, 2024
1e4b63d
Merge branch 'main' into f1032-remove-blank-lines-after-and-before-pa…
IndrajeetPatil May 12, 2024
e744159
use only a single transformer
IndrajeetPatil May 14, 2024
2a98c4d
Update strict.Rmd
IndrajeetPatil May 14, 2024
4b12010
add a test that mixes LBB with (
IndrajeetPatil May 15, 2024
0a1c8b6
also add test for mixing `[ `and `(`
IndrajeetPatil May 15, 2024
8c93aaf
Update pre-commit.yaml
IndrajeetPatil May 15, 2024
671f3f4
Update pre-commit.yaml
IndrajeetPatil May 15, 2024
b480577
Revert "Update pre-commit.yaml"
IndrajeetPatil May 15, 2024
18bae50
Update pre-commit.yaml
IndrajeetPatil May 15, 2024
f9d4ab4
merge with main
IndrajeetPatil May 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions R/rules-spaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,34 @@ remove_space_before_opening_paren <- function(pd_flat) {
pd_flat
}

remove_space_after_opening_paren <- function(pd_flat) {
paren_after <- pd_flat$token %in% c("'('", "'['", "LBB")
remove_space_after_opening_paren <- function(pd_flat, strict) {
braces <- c("'('", "'['", "LBB")
IndrajeetPatil marked this conversation as resolved.
Show resolved Hide resolved
paren_after <- pd_flat$token %in% braces
if (!any(paren_after)) {
return(pd_flat)
}
# remove blank lines after opening braces
if (strict) {
IndrajeetPatil marked this conversation as resolved.
Show resolved Hide resolved
pd_flat$lag_newlines[
lag(pd_flat$token %in% braces) & pd_flat$lag_newlines > 1L
] <- 1L
}
pd_flat$spaces[paren_after & (pd_flat$newlines == 0L)] <- 0L
pd_flat
}

remove_space_before_closing_paren <- function(pd_flat) {
paren_after <- pd_flat$token %in% c("')'", "']'")
remove_space_before_closing_paren <- function(pd_flat, strict) {
braces <- c("')'", "']'")
paren_after <- pd_flat$token %in% braces
if (!any(paren_after)) {
return(pd_flat)
}
# remove blank lines before closing braces
if (strict) {
pd_flat$lag_newlines[
pd_flat$token %in% braces & pd_flat$lag_newlines > 1L
] <- 1L
}
paren_before <- lead(paren_after, default = FALSE)
pd_flat$spaces[paren_before & (pd_flat$newlines == 0L)] <- 0L
pd_flat
Expand Down
10 changes: 8 additions & 2 deletions R/style-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ tidyverse_style <- function(scope = "tokens",
}
space_manipulators <- if ("spaces" %in% scope) {
list(
remove_space_before_closing_paren = remove_space_before_closing_paren,
remove_space_before_closing_paren = purrr::partial(
remove_space_before_closing_paren,
strict = strict
),
remove_space_before_opening_paren = if (strict) {
remove_space_before_opening_paren
},
Expand All @@ -105,7 +108,10 @@ tidyverse_style <- function(scope = "tokens",
spacing_around_op = purrr::partial(set_space_around_op,
strict = strict
),
remove_space_after_opening_paren = remove_space_after_opening_paren,
remove_space_after_opening_paren = purrr::partial(
remove_space_after_opening_paren,
strict = strict
),
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
{1 + 3}
{2 + sin(pi)}
}

{

{1 + 3}
{2 + sin(pi)}


}

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@
2 + sin(pi)
}
}

{
{
1 + 3
}
{
2 + sin(pi)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@ a <- function(x, y, z) {
x[i] +1
}
}


if (

require("logspline") &&
require("rstanarm")



) {

NULL


}
Loading
Loading