Skip to content

Commit 6db6eff

Browse files
Merge pull request #1195 from r-lib/f1032-remove-blank-lines-after-and-before-parens
Remove blank lines after opening and before closing braces
2 parents 4256522 + f9d4ab4 commit 6db6eff

28 files changed

+291
-24
lines changed

.github/workflows/check-full.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
# use 4.1 to check with rtools40's older compiler
2626
- { os: windows-latest, r: "4.1" }
2727

28-
- { os: ubuntu-latest, r: "devel", http-user-agent: "release" }
29-
- { os: ubuntu-latest, r: "devel", locale: "en_US" }
28+
- { os: ubuntu-latest, r: "devel", locale: "en_US", http-user-agent: "release" }
3029
#- { os: ubuntu-latest, r: "release", locale: "zh_CN" }
30+
- { os: ubuntu-latest, r: "release" }
3131
- { os: ubuntu-latest, r: "oldrel-1" }
3232
- { os: ubuntu-latest, r: "oldrel-2" }
3333
- { os: ubuntu-latest, r: "oldrel-3" }

.github/workflows/pre-commit.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@ jobs:
2424
- uses: actions/checkout@v4
2525
with:
2626
fetch-depth: 0
27-
- name: Install system dependencies
28-
if: runner.os == 'Linux'
29-
run: |
30-
# your system installation code here
31-
# sudo apt-get install -y libcurl4-openssl-dev
3227
- name: Set up Python
33-
uses: actions/setup-python@v5
28+
uses: actions/setup-python@v5.1.0
3429
with:
3530
python-version: "3.9"
3631
architecture: "x64"
3732
- name: Run pre-commit
3833
uses: pre-commit/[email protected]
39-
env:
34+
env:
4035
SKIP: pkgdown
4136
- name: Commit files
4237
if: failure() && startsWith(github.ref, 'refs/heads')

R/rules-line-breaks.R

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ remove_line_breaks_in_fun_dec <- function(pd) {
244244
pd
245245
}
246246

247-
#'
247+
248248
add_line_break_after_pipe <- function(pd) {
249249
is_pipe <- pd$token %in% c("SPECIAL-PIPE", "PIPE")
250250
pd$lag_newlines[lag(is_pipe) & pd$lag_newlines > 1L] <- 1L
@@ -417,3 +417,25 @@ set_line_break_after_ggplot2_plus <- function(pd) {
417417
}
418418
pd
419419
}
420+
421+
422+
remove_empty_lines_after_opening_and_before_closing_braces <- function(pd) {
423+
opening_braces <- c("'('", "'['", "LBB")
424+
closing_braces <- c("')'", "']'")
425+
426+
paren_after <- pd$token %in% opening_braces
427+
if (any(paren_after)) {
428+
pd$lag_newlines[
429+
lag(pd$token %in% opening_braces) & pd$lag_newlines > 1L
430+
] <- 1L
431+
}
432+
433+
paren_before <- pd$token %in% closing_braces
434+
if (any(paren_before)) {
435+
pd$lag_newlines[
436+
pd$token %in% closing_braces & pd$lag_newlines > 1L
437+
] <- 1L
438+
}
439+
440+
pd
441+
}

R/rules-spaces.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ remove_space_after_unary_pm_nested <- function(pd) {
131131
}
132132

133133
remove_space_before_opening_paren <- function(pd_flat) {
134-
paren_after <- pd_flat$token %in% c("'('", "'['", "LBB")
134+
opening_braces <- c("'('", "'['", "LBB")
135+
paren_after <- pd_flat$token %in% opening_braces
135136
if (!any(paren_after)) {
136137
return(pd_flat)
137138
}
@@ -141,7 +142,8 @@ remove_space_before_opening_paren <- function(pd_flat) {
141142
}
142143

143144
remove_space_after_opening_paren <- function(pd_flat) {
144-
paren_after <- pd_flat$token %in% c("'('", "'['", "LBB")
145+
opening_braces <- c("'('", "'['", "LBB")
146+
paren_after <- pd_flat$token %in% opening_braces
145147
if (!any(paren_after)) {
146148
return(pd_flat)
147149
}
@@ -150,7 +152,8 @@ remove_space_after_opening_paren <- function(pd_flat) {
150152
}
151153

152154
remove_space_before_closing_paren <- function(pd_flat) {
153-
paren_after <- pd_flat$token %in% c("')'", "']'")
155+
closing_braces <- c("')'", "']'")
156+
paren_after <- pd_flat$token %in% closing_braces
154157
if (!any(paren_after)) {
155158
return(pd_flat)
156159
}

R/style-guides.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ tidyverse_style <- function(scope = "tokens",
130130

131131
line_break_manipulators <- if ("line_breaks" %in% scope) {
132132
list(
133+
remove_empty_lines_after_opening_and_before_closing_braces =
134+
remove_empty_lines_after_opening_and_before_closing_braces,
133135
set_line_break_around_comma_and_or = set_line_break_around_comma_and_or,
134136
set_line_break_after_assignment = set_line_break_after_assignment,
135137
set_line_break_before_curly_opening = set_line_break_before_curly_opening,

tests/testthat/indention_curly_brackets/multi_line_curly_only-in.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@
22
{1 + 3}
33
{2 + sin(pi)}
44
}
5+
6+
{
7+
8+
# some additions
9+
{1 + 3}
10+
{2 + sin(pi)}
11+
12+
# nothing to see here
13+
14+
}

tests/testthat/indention_curly_brackets/multi_line_curly_only-out.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@
66
2 + sin(pi)
77
}
88
}
9+
10+
{
11+
# some additions
12+
{
13+
1 + 3
14+
}
15+
{
16+
2 + sin(pi)
17+
}
18+
19+
# nothing to see here
20+
}

tests/testthat/indention_curly_brackets/multi_line_curly_while_for_if_fun-in.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,18 @@ a <- function(x, y, z) {
88
x[i] +1
99
}
1010
}
11+
12+
13+
if (
14+
15+
require("logspline") &&
16+
require("rstanarm")
17+
18+
19+
20+
) {
21+
22+
NULL
23+
24+
25+
}

tests/testthat/indention_curly_brackets/multi_line_curly_while_for_if_fun-out.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ a <- function(x, y, z) {
88
x[i] + 1
99
}
1010
}
11+
12+
13+
if (
14+
require("logspline") &&
15+
require("rstanarm")
16+
) {
17+
NULL
18+
}

tests/testthat/indention_round_brackets/arithmetic_start-in.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,16 @@
33
3 + 4
44
)
55
)
6+
7+
(
8+
9+
1 +
10+
2 + (
11+
# the space below is intentional
12+
13+
3 + 4
14+
# but the one here isn't
15+
16+
17+
)
18+
)

0 commit comments

Comments
 (0)