library(styler)

styler::cache_deactivate()
## Deactivated cache.
style_base <- tidyverse_style()

get_progression <- function(x) {
  out <- collections::deque()
  i <- length(x)
  while (i > 0) {
    out$pushleft(x)
    x[[i]] <- head(x[[i]], -1)
    if (length(x[[i]]) == 0) {
      i <- i - 1
    }
  }
  out$as_list()
}

style_progression <- get_progression(style_base[c("space", "indention", "line_break", "token")])

code <- "
x <- function(
    a,
    b
) {

  # some-comment
  y

}
"

result <- NULL
for (i in seq_along(style_progression)) {
  my_style <- style_progression[[i]]
  new_result <- styler::style_text(code, style = function() {
    style <- style_base
    style[names(my_style)] <- my_style
    style
  })

  if (!identical(result, new_result)) {
    print(i)
    print(waldo::compare(result, new_result))
    if (i > 1) {
      print(tail(tail(purrr::compact(my_style), 1)[[1]], 1))
    }
    print(new_result)
    result <- new_result
  }
}
## [1] 1
## `old` is NULL
## `new` is an S3 object of class <vertical>, a character vector
## x <- function(
## a,
## b
## ) {
## 
## # some-comment
## y
## 
## }
## [1] 20
## `old`: "x <- function(" "a,"   "b"   ") {" "" "# some-comment"   "y"   "" "}"
## `new`: "x <- function(" "  a," "  b" ") {" "" "  # some-comment" "  y" "" "}"
## $indent_braces
## <partialised>
## function (...) 
## indent_braces(indent_by = indent_by, ...)
## <environment: 0x149dd43d8>
## 
## x <- function(
##   a,
##   b
## ) {
## 
##   # some-comment
##   y
## 
## }
## [1] 21
##     old                | new                   
## [1] "x <- function("   | "x <- function("   [1]
## [2] "  a,"             - "    a,"           [2]
## [3] "  b"              - "    b"            [3]
## [4] ") {"              - "    ) {"          [4]
## [5] ""                 | ""                 [5]
## [6] "  # some-comment" | "  # some-comment" [6]
## [7] "  y"              | "  y"              [7]
## $unindent_fun_dec
## function (pd, indent_by = 2L) 
## {
##     if (is_function_declaration(pd)) {
##         idx_closing_brace <- which(pd$token %in% "')'")
##         fun_dec_head <- seq2(2L, idx_closing_brace)
##         if (is_double_indent_function_declaration(pd, indent_by = indent_by)) {
##             pd$indent[fun_dec_head] <- 2L * indent_by
##         }
##         else {
##             pd$indent[fun_dec_head] <- 0L
##         }
##     }
##     pd
## }
## <bytecode: 0x149ebd650>
## <environment: namespace:styler>
## 
## x <- function(
##     a,
##     b
##     ) {
## 
##   # some-comment
##   y
## 
## }
## [1] 30
##     old                | new                   
## [1] "x <- function("   | "x <- function("   [1]
## [2] "    a,"           | "    a,"           [2]
## [3] "    b"            - "    b) {"         [3]
## [4] "    ) {"          -                       
## [5] ""                 | ""                 [4]
## [6] "  # some-comment" | "  # some-comment" [5]
## [7] "  y"              | "  y"              [6]
## $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_indention) {
##             pd$lag_newlines[lag(pd$token == "'('")] <- 1L
##         }
##     }
##     pd
## }
## <bytecode: 0x12a042468>
## <environment: namespace:styler>
## 
## x <- function(
##     a,
##     b) {
## 
##   # some-comment
##   y
## 
## }
## [1] 31
## `old`: "x <- function(" "    a," "    b) {" "" "  # some-comment" "  y" "" "}"
## `new`: "x <- function(" "    a," "    b) {"    "  # some-comment" "  y"    "}"
## $style_line_break_around_curly
## <partialised>
## function (...) 
## style_line_break_around_curly(strict, ...)
## <environment: 0x149dd43d8>
## 
## x <- function(
##     a,
##     b) {
##   # some-comment
##   y
## }