Skip to content
Permalink
Browse files

Merge pull request #372 from lorenzwalthert/fix-inention

- Fix indention (#372).
  • Loading branch information...
lorenzwalthert committed Mar 14, 2018
2 parents 01681bc + 1b5ee66 commit 53ae5e10f929967ebe9afa60429167ce11f32d6f
@@ -188,21 +188,32 @@ needs_indention <- function(pd,

#' Check whether indention is needed
#'
#' Determine whether the tokens corresponding to `potential_trigger_pos` should
#' cause indention, considering that there might be other potential triggers
#' `other_trigger_tokens` that are going to cause indention.
#' Indention is needed if the two conditions apply:
#'
#' * there is no multi-line token between the trigger and the first line break.
#' * there is no other token between the potential trigger and the first line
#' break that is going to cause indention.
#'
#' break that is going to cause indention. Note that such an other trigger
#' only causes indention if there is a line break after that other triggering
#' token, not otherwise. If it causes indention, it is said to be an active
#' trigger, if it does not, it is called an inactive trigger.
#' See 'Details' for an example where there is an other trigger token, but
#' since the next token is on the same line as the other trigger,
#' the trigger is passive.
#' @param pd A parse table.
#' @param potential_trigger_pos the index of the token in the parse table
#' for which it should be checked whether it should trigger indention.
#' @return Returns `TRUE` if indention is needed, `FALSE` otherwise.
#' @param other_trigger_tokens Other tokens that are going to cause indention
#' if on the same line as the token corresponding to `potential_trigger`.
#' if on the same line as the token corresponding to `potential_trigger` and
#' directly followed by a line break.
#' @return `TRUE` if indention is needed, `FALSE` otherwise.
#' @importFrom rlang seq2
#' @keywords internal
#' @examples
#' style_text("call(named = c, \nnamed = b)", strict = FALSE)
needs_indention_one <- function(pd,
potential_trigger_pos,
other_trigger_tokens) {
@@ -219,11 +230,17 @@ needs_indention_one <- function(pd,
potential_trigger_pos
)

other_trigger_on_same_line <-
pd$token[remaining_row_idx_between_trigger_and_line_break] %in%
other_trigger_tokens
other_trigger_on_same_line <- (
pd$token[remaining_row_idx_between_trigger_and_line_break] %in%
other_trigger_tokens
)
line_break_after_other_trigger <-
pd$lag_newlines[remaining_row_idx_between_trigger_and_line_break + 1L] > 0L

active_trigger_on_same_line <-
other_trigger_on_same_line & line_break_after_other_trigger

!any(multi_line_token) & !any(other_trigger_on_same_line)
!any(multi_line_token) & !any(active_trigger_on_same_line)
}


Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,37 @@
call(a,
b)

call(a,
b = 3)

call(a = 1, b =
3)

call(a =
1, b = 3)

call(a = 1,
b = 3
)

call(
a = 1,
b = 3
)

call(
a =
1,
b = 3
)

call(
a =
1, b = 3
)

call(
a =
1, b =
3
)

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,37 @@
call(a,
b)

call(a,
b = 3)

call(a = 1, b =
3)

call(a =
1, b = 3)

call(a = 1,
b = 3
)

call(
a = 1,
b = 3
)

call(
a =
1,
b = 3
)

call(
a =
1, b = 3
)

call(
a =
1, b =
3
)
@@ -0,0 +1,6 @@
context("test-indention_fun_calls.R")

test_that("edge cases work", {
expect_warning(test_collection("indention_fun_calls",
transformer = style_text, strict = FALSE), NA)
})
@@ -45,14 +45,15 @@ test_that("if and ifelse interacting with curly braces works", {

test_that("edge cases work", {
expect_warning(test_collection("indention_multiple",
"edge_",
"edge_strict",
transformer = style_text), NA)

})

test_that("token / braces interaction works", {
expect_warning(test_collection("indention_multiple",
"fun_for_new_line",
transformer = style_text), NA)


})

0 comments on commit 53ae5e1

Please sign in to comment.
You can’t perform that action at this time.