Skip to content

No blank lines in function headers #630

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 5 commits into from
Apr 11, 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
21 changes: 9 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# All available hooks: https://pre-commit.com/hooks.html
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.0.0.9027
rev: v0.0.0.9038
hooks:
# - id: lintr
# - id: style-files Does style *-in.R files in tests otherwise!
- id: parsable-R
- id: no-browser-statement
# - id: lintr
- id: readme-rmd-rendered
# R package development
- id: roxygenize
- id: use-tidy-description
- id: deps-in-desc
- id: spell-check
- id: style-files
args: [--style_pkg=styler, --style_fun=tidyverse_style]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v2.5.0
hooks:
- id: check-added-large-files
args: ['--maxkb=200']
- repo: https://github.com/lorenzwalthert/precommit-markdown-link-check
rev: v0.0.0.9002 # Use the sha / tag you want to point at
hooks:
- id: markdown-link-check
- id: end-of-file-fixer
exclude: '\.Rd'
3 changes: 1 addition & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Major changes

- blank lines in function calls and headers are now removed (#629, #630).

## Minor chnages and fixes

Expand All @@ -10,7 +11,6 @@
- typos in documentation (#618, #614).



# styler 1.3.2

Release upon request by the CRAN team.
Expand Down Expand Up @@ -435,4 +435,3 @@ specify_reindention(
)
initialize_default_attributes(pd_flat)
```

20 changes: 15 additions & 5 deletions R/rules-line-break.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ set_line_break_before_curly_opening <- function(pd) {
}


set_line_break_around_comma <- function(pd) {
set_line_break_around_comma <- function(pd, strict) {
comma_with_line_break_that_can_be_removed_before <-
(pd$token == "','") &
(pd$lag_newlines > 0) &
(pd$token_before != "COMMENT") &
(lag(pd$token) != "'['")

pd$lag_newlines[comma_with_line_break_that_can_be_removed_before] <- 0L
pd$lag_newlines[lag(comma_with_line_break_that_can_be_removed_before)] <- 1L
pd
Expand Down Expand Up @@ -169,9 +170,10 @@ remove_line_break_before_round_closing_after_curly <- function(pd) {
pd
}

remove_line_break_before_round_closing_fun_dec <- function(pd) {
remove_line_breaks_in_fun_dec <- function(pd) {
if (is_function_dec(pd)) {
round_after <- pd$token == "')'" & pd$token_before != "COMMENT"
pd$lag_newlines[pd$lag_newlines > 1L] <- 1L
pd$lag_newlines[round_after] <- 0L
}
pd
Expand Down Expand Up @@ -267,9 +269,17 @@ set_line_break_before_closing_call <- function(pd, except_token_before) {

#' @rdname set_line_break_if_call_is_multi_line
#' @keywords internal
remove_line_break_in_empty_fun_call <- function(pd) {
if (is_function_call(pd) && nrow(pd) == 3) {
pd$lag_newlines[3] <- 0L
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
}
if (nrow(pd) == 3) {
pd$lag_newlines[3] <- 0L
}
}
pd
}
Expand Down
6 changes: 3 additions & 3 deletions R/style-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ tidyverse_style <- function(scope = "tokens",
set_line_break_before_curly_opening,
remove_line_break_before_round_closing_after_curly =
if (strict) remove_line_break_before_round_closing_after_curly,
remove_line_break_before_round_closing_fun_dec =
if (strict) remove_line_break_before_round_closing_fun_dec,
remove_line_breaks_in_fun_dec =
if (strict) remove_line_breaks_in_fun_dec,
style_line_break_around_curly = partial(
style_line_break_around_curly,
strict
Expand All @@ -139,7 +139,7 @@ tidyverse_style <- function(scope = "tokens",
except_token_before = "COMMENT"
)
},
remove_line_break_in_empty_fun_call,
purrr::partial(remove_line_break_in_fun_call, strict = strict),
add_line_break_after_pipe = if (strict) add_line_break_after_pipe,
set_linebreak_after_ggplot2_plus = if (strict) set_linebreak_after_ggplot2_plus
)
Expand Down
150 changes: 77 additions & 73 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
yihui
xfun
Visit'em
unnest
unlinkunindention
unindent
unindent
unexplainable
uncached
Tidyverse
tidyverse
tidyeval
tibbles
tibble
testthat
stylerignore
stylerignored
StackOverflow
Rprofile
rprofile
rplumber
Roxygen
roxygen
Rnw
rnw
Rmd
rmd
RMarkdown
rlang
reprex
reindention
reindented
rebased
README
readme
rds
precommit
pre
pos
pkgdown
parsable
NUM
macOS
lorenzwalthert
lifecycle
LF
levelName
knitr
ixmypi
invasiveness
innode
infinitively
https
forcond
filetype
expr EQ
EOLs
EOL
EOF
emacs
DSLs
dontshowdontrun
donttest
dont
dir
dec
cran
CONST
config
codecov
CMD
cancelling

Addin
Addins
AppVeyor
apriori
arg
AST
benchmarking
cancelling
chnages
CMD
codecov
config
CONST
cran
dec
dir
dont
dontshowdontrun
donttest
DSLs
emacs
EOF
EOL
EOLs
expr
expr EQ
filetype
forcond
funct
https
infinitively
innode
invasiveness
ixmypi
knitr
levelName
LF
lifecycle
lorenzwalthert
macOS
NUM
parsable
pgkdown
pkgdown
pos
pre
precommit
rds
readme
README
rebased
reindented
reindention
reprex
rlang
RMarkdown
rmd
Rmd
rnw
Rnw
roxygen
Roxygen
rplumber
rprofile
Rprofile
StackOverflow
styler
stylerignore
stylerignored
stylers
testthat
tibble
tibbles
tidyeval
tidyverse
Tidyverse
uncached
unexplainable
unindent
unlinkunindention
unnest
Visit'em
xfun
yihui
4 changes: 2 additions & 2 deletions man/set_line_break_if_call_is_multi_line.Rd

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

1 change: 0 additions & 1 deletion tests/testthat/alignment/named-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ call(
# algorithm: aligned. human: aligned.
call(
x = 1, n = 33, z = "333",

xy = 2,
)

Expand Down
23 changes: 20 additions & 3 deletions tests/testthat/fun_dec/line_break_fun_dec-in.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
a <- function(x, #
y
) {
y) {
x - 1
}

Expand All @@ -13,6 +12,24 @@ a <- function(x, #

a <- function(x, #
y #
) {
) {
y
}


a <- function(x,
y) {
x - 1
}

a <- function(x,
#
y) {
x - 1
}

a <- function(x,

y) {
x - 1
}
Loading