Skip to content

useBraces - add asNeeded option as stricter preferNone #762

@Squidgical

Description

@Squidgical

Consider this code;

while (condition) yield aBigCall({
  the: "expression",
  spans: "many",
  lines,
})

when formatting with useBraces: "preferNone";

while (condition) {
  yield aBigCall({
    the: "expression",
    spans: "many",
    lines,
  })
}

however my desired output is the exact same as the input. My philosophy is;

  • I should not write any code that is redundant
  • statements whose bodies contain only one expression/statement do not need braces
  • braces on such statements are redundant
  • I should not write braces on such statements

It would be nice to have an option which refuses to add or keep braces if they only enclose a single expression, regardless of whether that expression spans 3 characters or a million lines.

To me, this is what preferNone means; "prefer to use no braces, unless the code would behave incorrectly without them."

The current implementation of preferNone seems to be; "prefer to [...] without them or the code matches one of these arbitrary cases." This isn't preferring none, but instead preferring a particular opinionated style.


I would like to request another option asNeeded which will only permit braces where strictly necessary for functionality, and will enforce that single-expression bodies are not braced.

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