# ------------------------------------------------------------------------
# Miscellaneous

function(a_really_long_argument_name_to_break_on, and_here_is_another_one_please_break_me, and_this) {
  a
}

function(a = {
  1
}, b) {
  1
}

# ------------------------------------------------------------------------
# Autobracing

# These stay flat
function() 1
function(a, b) 1
\() 1
\(a, b) 1

# Persistent line break in `parameters` triggers autobracing because the `body`
# is in the same `group()`
function(
  a, b) 1

\(
  a, b) 1

# Persistent line break in `parameters` triggers autobracing because the `body`
# is in the same `group()`
function(
  a, b
) 1

# Persistent line break in `body` triggers autobracing
function(a, b)
  1

\(a, b)
  1

# This snaps back to one line
function
(a, b) 1

function(a_really_long_argument_name_to_break_on, and_here_is_another_one_please_break_me, and_this) a

function(a_really_long_argument_name_to_break_on, and_this) a_really_long_argument_name_to_break_on

# ------------------------------------------------------------------------
# Comments

function # leads function
() {}

function
# leads function
() {}

function( # dangles ()
) {}

function(
  # dangles ()
) {}

function() {
  # dangles {}
}

function() a # trails function

function() # leads `a`
{
  a
}

function() # leads `a`
{
  # an inner comment
  a
}

function() # dangles {}
{
}

function() # dangles {}
{}

function() # dangles {}
{
  # an inner comment but empty `{}`
}

function() # leads `a`
  a

# Not much we can do here, it's not enclosed by the `function_definition` node
# so it ends up trailing the `}` of the function. This is consistent with
# non-enclosed comments in if/else and loops.
function()
  a # trails function

function(
  # leads `a`
  a
) {
  # comment
}

function(
  a # trails `a`
) {
  # comment
}

function(
  a
  # trails `a`
) {
  # comment
}

# ------------------------------------------------------------------------
# User requested line break

# A line break before the first parameter forces expansion

# So this function definition stays expanded even though it fits on one line
fn <- function(
  a,
  b
) {
  body
}

# This flattens to one line
fn <- function(a,
  b
) {
  body
}

# This flattens to one line
fn <- function(a, b
) {
  body
}

# Expansion doesn't propagate to the `c(1, 2, 3)`
fn <- function(
  a,
  b = c(1, 2, 3)
) {
  body
}

# Dots - this expands
fn <- function(
  ..., a, b
) {
  body
}

# Dots - this flattens
fn <- function(...,
  a, b
) {
  body
}

# User requested expansion of the `c()` call forces expansion of
# the entire function definition
fn <- function(a, b = c(
  1, 2, 3)) {
  body
}
