Skip to content

Don't remove blank lines around comments #635

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

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repos:
- id: spell-check
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
exclude: 'tests/testthat/.*/*\.R'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Major changes

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

## Minor chnages and fixes

Expand Down
4 changes: 1 addition & 3 deletions R/rules-line-break.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,7 @@ remove_line_break_in_fun_call <- function(pd, strict) {
if (is_function_call(pd)) {
# no blank lines within function calls
if (strict) {
pd$lag_newlines[lag(pd$token == "','") & pd$lag_newlines > 1] <- 1L

pd$lag_newlines[lag(pd$token == "COMMENT") & pd$lag_newlines > 0] <- 1L
pd$lag_newlines[lag(pd$token == "','") & pd$lag_newlines > 1 & pd$token != "COMMENT"] <- 1L
}
if (nrow(pd) == 3) {
pd$lag_newlines[3] <- 0L
Expand Down
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ emacs
EOF
EOL
EOLs
EQ
expr
expr EQ
filetype
Expand Down Expand Up @@ -64,6 +65,7 @@ rplumber
rprofile
Rprofile
StackOverflow
STR
styler
stylerignore
stylerignored
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/line_breaks_fun_call/blank-strict-in.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ call(

"w"
)

call(
1,
2,



# comment

1,
2,

3
)
50 changes: 35 additions & 15 deletions tests/testthat/line_breaks_fun_call/blank-strict-in_tree

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

14 changes: 14 additions & 0 deletions tests/testthat/line_breaks_fun_call/blank-strict-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ call(

call(
# comment

1
)

Expand All @@ -12,3 +13,16 @@ call(
1,
"w"
)

call(
1,
2,



# comment

1,
2,
3
)