Skip to content

Allow preserving style for single-line if expressions #516

@serenity4

Description

@serenity4

Single-line if expressions currently get split into multiple lines. Would it be possible to keep the style to preserve the first version below?

Before formatting:

function f()
  if rand() < 0.5 return 2 end
  0
end

After formatting (if gets split):

function f()
    if rand() < 0.5
        return 2
    end
    0
end

While the splitting is probably desired in most cases, the case above is equivalent to a short-circuiting && so it's a bit of a corner case, but still it could be made more readable by keeping it in one line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions