Skip to content

detect double indented function declarations with one line break only as double indented #1094

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
Jan 30, 2023
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
3 changes: 2 additions & 1 deletion R/rules-line-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,14 @@ remove_line_break_before_round_closing_after_curly <- function(pd) {

remove_line_breaks_in_fun_dec <- function(pd) {
if (is_function_declaration(pd)) {
is_double_indention <- is_double_indent_function_declaration(pd)
round_after <- (
pd$token == "')'" | pd$token_before == "'('"
) &
pd$token_before != "COMMENT"
pd$lag_newlines[pd$lag_newlines > 1L] <- 1L
pd$lag_newlines[round_after] <- 0L
if (is_double_indent_function_declaration(pd)) {
if (is_double_indention) {
pd$lag_newlines[lag(pd$token == "'('")] <- 1L
}
}
Expand Down
13 changes: 10 additions & 3 deletions tests/testthat/unindention/mixed-double-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function(
}


function(x, y) {
function(
x, y) {
1
}

Expand All @@ -70,9 +71,15 @@ function(x,


# last brace
function(x, y) NULL
function(
x, y) {
NULL
}

function(x, y) NULL
function(
x, y) {
NULL
}

function(
x,
Expand Down