Skip to content

Multiline anonymous functions should forcibly have their body wrapped in { } #321

@DavisVaughan

Description

@DavisVaughan
\(x) if (is.na(x)) "CRAN" else cli::cli_fmt(cli::cli_text("{.field {x}} field in DESCRIPTION"))

Currently formatted as

\(x)
  if (is.na(x)) "CRAN" else
    cli::cli_fmt(cli::cli_text("{.field {x}} field in DESCRIPTION"))

I think in this case it should really be:

\(x) {
  if (is.na(x)) {
    "CRAN"
  } else {
    cli::cli_fmt(cli::cli_text("{.field {x}} field in DESCRIPTION"))
  }
}

We already planned to force multiline if/else to be wrapped in { } (it's related to #225 and tidyverse/style#240), but I think we should also apply this to function logic too.

i.e. if a user requested line break is already there before the body, or the whole thing can't fit on one line, then forcibly add { }. Because as soon as you add a second statement, you need them anyways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions