knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(reflow)
options(reflow.quiet = FALSE)

rs <- rules(
  "function header opening paren should not be preceded by whitespace" = rule(
    "function", ws(0), "expr"
  ),
  "function header closing paren should have a single space before an opening curly brace" = rule(
    on = list("function", "expr", pexpr("{")),
    "function", "expr", ws(1), pexpr("{")
  ),
  "multiline function headers should leave an empty line before the function body" = rule(
    on = list("function", multiline("expr"), pexpr("{")),
    "function", multiline("expr"), pexpr("{", ws(nl=2))
  ),
  "parameter assignments should always be surrounded by single spaces" = rule(
    on = "eq_formals",
    ws(1), "=", ws(1)
  ),
  "multiline expressions should be indented by one level" = rule(
    "{",
    ws(nl = 1),
    indent(zero_or_more(any_token(), until = "}")),
    ws(nl = 1),
    "}"
  )
)

match_style(rs, "
test <- function() 1L

test <- function (a = 1L,
  b  = 3){

  1 + 2L
  {
    1 + 2
  }
}
")


dgkf/reflow documentation built on Dec. 19, 2021, 11:05 p.m.