Skip to content

Smart linebreak for expressions #6432

@cometkim

Description

@cometkim

#6380 will be landed in v11. This changes the user's coding experience for the better.

So I wonder if the same improvement can be applied to other comma-separated things like literals and some expressions, which are currently formatted by the line-width rule.

arrays:

let a = ["foo", "bar", "baz"]

// into

let a = [
  "foo",
  "bar",
  "baz", // automatically add trailing comma will be nicer
]

types/records/objects

let a = {foo: 1, bar: 2, baz: ["foo", "bar", "baz"]}

// into

let a = {
  foo: 1,
  bar: 2,
  baz: ["foo", "bar", "baz"],
}

// and then

let a = {
  foo: 1,
  bar: 2,
  baz: [
    "foo",
    "bar",
    "baz",
  ],
}

fn applications:

// same as above

let _ = func(~param1="foo", ~param2=["foo", "bar"])

// into

let _ = func(
  ~param1="foo",
  ~param2=["foo", "bar"],
)

// and then

let _ = func(
  ~param1="foo",
  ~param2=[
    "foo",
    "bar",
  ],
)

And also I strongly want similar to be in JSX but not sure how much more complicated it will

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status

Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions