Skip to content

Commit a2014dc

Browse files
address review feedback
1 parent 1166e3b commit a2014dc

File tree

6 files changed

+28
-37
lines changed

6 files changed

+28
-37
lines changed

R/rules-line-breaks.R

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -449,26 +449,13 @@ remove_empty_lines_after_opening_and_before_closing_braces <- function(pd) {
449449
}
450450

451451

452-
#' Reduce multiple blank lines to a maximum number of allowed blank lines
453-
#' @param pd_flat A flat parse table.
454-
#' @param allowed_blank_lines The maximum number of allowed blank lines between code elements. Default is `2L`.
455-
#' @keywords internal
456-
reduce_extra_blank_lines_between_scopes <- function(pd_flat, allowed_blank_lines = 2L) {
452+
reduce_extra_blank_lines_between_scopes <- function(pd, allowed_blank_lines = 2L) {
457453
# Calculate the maximum allowed lag_newlines
458-
max_lag_newlines <- allowed_blank_lines + 1L # +1 accounts for the line with the previous token
459-
460-
# Create a copy of lag_newlines to track modifications
461-
modified_lag_newlines <- pd_flat$lag_newlines
454+
max_lag_newlines <- allowed_blank_lines + 1L # +1 accounts for the line with the previous token
462455

463-
# Iterate through the dataframe to reduce consecutive blank lines
464-
for (i in seq_along(modified_lag_newlines)) {
465-
if (modified_lag_newlines[i] > max_lag_newlines) {
466-
modified_lag_newlines[i] <- max_lag_newlines
467-
}
468-
}
456+
# cap lag_newlines at max_lag_newlines
457+
pd$lag_newlines <- pmin(pd$lag_newlines, max_lag_newlines)
469458

470-
# Update the original data frame
471-
pd_flat$lag_newlines <- modified_lag_newlines
472-
473-
return(pd_flat)
459+
pd
474460
}
461+

R/style-guides.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ tidyverse_style <- function(scope = "tokens",
139139
if (strict) remove_line_break_before_round_closing_after_curly,
140140
remove_line_breaks_in_fun_dec =
141141
if (strict) remove_line_breaks_in_fun_dec,
142-
reduce_extra_blank_lines_between_scopes = reduce_extra_blank_lines_between_scopes,
142+
reduce_extra_blank_lines_between_scopes =
143+
if (strict) reduce_extra_blank_lines_between_scopes,
143144
style_line_break_around_curly = partial(
144145
style_line_break_around_curly,
145146
strict

man/reduce_extra_blank_lines_between_scopes.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/testthat/line_breaks_and_other/pipe_and_comment-in.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,14 @@ f %>% g()
99

1010

1111
h %>% i()
12+
13+
14+
15+
16+
17+
# some comment
18+
19+
20+
21+
22+
j %>% k()

tests/testthat/line_breaks_and_other/pipe_and_comment-out.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ f %>% g()
66

77

88
h %>% i()
9+
10+
11+
# some comment
12+
13+
14+
j %>% k()

tests/testthat/line_breaks_fun_call/blank-non-strict-out.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ call(
99
)
1010

1111

12+
13+
14+
1215
call(
1316
x = 2,
1417
1,

0 commit comments

Comments
 (0)