Skip to content

Commit 521f700

Browse files
Merge pull request #635 from lorenzwalthert/issue-632
- Don't remove blank lines around comments (#632).
2 parents 2ce6da3 + f99d363 commit 521f700

File tree

7 files changed

+69
-19
lines changed

7 files changed

+69
-19
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repos:
1111
- id: spell-check
1212
- id: style-files
1313
args: [--style_pkg=styler, --style_fun=tidyverse_style]
14+
exclude: 'tests/testthat/.*/*\.R'
1415
- repo: https://github.com/pre-commit/pre-commit-hooks
1516
rev: v2.5.0
1617
hooks:

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Major changes
44

5-
- blank lines in function calls and headers are now removed (#629, #630).
5+
- blank lines in function calls and headers are now removed, for the former only
6+
when there are no comments before or after the blank line (#629, #630, #635).
67

78
## Minor chnages and fixes
89

R/rules-line-break.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,7 @@ remove_line_break_in_fun_call <- function(pd, strict) {
273273
if (is_function_call(pd)) {
274274
# no blank lines within function calls
275275
if (strict) {
276-
pd$lag_newlines[lag(pd$token == "','") & pd$lag_newlines > 1] <- 1L
277-
278-
pd$lag_newlines[lag(pd$token == "COMMENT") & pd$lag_newlines > 0] <- 1L
276+
pd$lag_newlines[lag(pd$token == "','") & pd$lag_newlines > 1 & pd$token != "COMMENT"] <- 1L
279277
}
280278
if (nrow(pd) == 3) {
281279
pd$lag_newlines[3] <- 0L

inst/WORDLIST

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ emacs
2222
EOF
2323
EOL
2424
EOLs
25+
EQ
2526
expr
2627
expr EQ
2728
filetype
@@ -64,6 +65,7 @@ rplumber
6465
rprofile
6566
Rprofile
6667
StackOverflow
68+
STR
6769
styler
6870
stylerignore
6971
stylerignored

tests/testthat/line_breaks_fun_call/blank-strict-in.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ call(
1616

1717
"w"
1818
)
19+
20+
call(
21+
1,
22+
2,
23+
24+
25+
26+
# comment
27+
28+
1,
29+
2,
30+
31+
3
32+
)

tests/testthat/line_breaks_fun_call/blank-strict-in_tree

Lines changed: 35 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ call(
44

55
call(
66
# comment
7+
78
1
89
)
910

@@ -12,3 +13,16 @@ call(
1213
1,
1314
"w"
1415
)
16+
17+
call(
18+
1,
19+
2,
20+
21+
22+
23+
# comment
24+
25+
1,
26+
2,
27+
3
28+
)

0 commit comments

Comments
 (0)