fn[]
fn[a]

# Inherits call-like behavior with trailing braced expressions
fn[a = { 1 + 1 }]
fn["description", {
  1 + 1
}]

# Leading hole hugs `[`
DT[, {
  # write each group to a different file
  fwrite(.SD, "name")
}, by=x]

# This is pretty good
DT[, by=x, {
  # write each group to a different file
  fwrite(.SD, "name")
}]

# ------------------------------------------------------------------------
# Holes

# Leading holes should hug the `[` token
fn[,]
fn[,,]

# Trailing holes get a trailing space
df[a,]

fn[a,,b,,]
fn[a_really_long_argument_here,,another_really_really_long_argument_to_test_this_feature,,]

# Holes are "invisible" when determining user requested expansion
# These all expand
fn[,
  x = 1
]
fn[
  ,
  x = 1
]
fn[
  , x = 1
]
fn[
  ,, x = 1
]

# ------------------------------------------------------------------------
# Holes and trailing inline functions / braced expressions

dt[, {
  1 + 1
}]
dt[, , j, {
  1 + 1
}]

dt[, function(x) {
  1 + x
}]
dt[, , j, function(x) {
  1 + x
}]

# ------------------------------------------------------------------------
# Dots

fn[...]
fn[..., a = 1]
fn[a = 1, ... = 2]
fn[a = 1, another_really_really_long_argument_to_test_this_feature, a_really_long_argument_here, ...]

# ------------------------------------------------------------------------
# Dot dot i

fn[..1, ..2]
fn[..1 = 1, ..2 = 2]

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

fn[
  # dangling special case
]

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

# A line break before the first argument forces expansion

# So this data dictionary stays expanded even though it fits on one line
df[
  df$col > 1,
  c(2, 3)
]

# This flattens to one line
df[df$col > 1,
  c(2, 3)
]

# This flattens to one line
df[df$col > 1, c(2, 3)
]

# Expanding the inner subset forces expansion of the outer subset
df[df$col > 7, map[
  names(df)
]]

# ------------------------------------------------------------------------
# User requested line break and leading holes

# Leading holes are "invisible" when computing user requested line breaks,
# so you can break the line before or after the hole as long as you are
# before the first argument.
# Starting from:
# dt[, j, by = col]

dt[
  , j, by = col]

dt[,
  j, by = col]

# No longer user requested expansion
dt[, j
  , by = col]

# ------------------------------------------------------------------------
# Comments "after" holes

# Common in data.table world
dt[,
  # comment
  x
]
