Skip to content

Unwanted line wrap in if/else conditions without curly brackets #869

@LilaRest

Description

@LilaRest

Hi ! Firstly, thanks for this amazing plugin.

Then, a thing I visually love is to write inline if/else conditions when their content is composed by a single simple line, e.g.,

// Comment 1 and Comment 2
if (balanceOf(msg.sender) >= 1000) priority = true;

// Instead of

// Comment 1
if (balanceOf(msg.sender) >= 1000) {
    // Comment 2
    priority = true;
}

This plugin seems to allow this except if the if statement is followed by an else if or else statement that uses curly brackets. So the above example will work but this one will receive a line wrap :

// Comment 1 and Comment 2
if (balanceOf(msg.sender) >= 1000)
    priority = true;

    // Comment 3
else {
    // ...multi-line stuff here
}

As you can see the else comment is not anymore aligned with the else statement, and the if statement is not inline anymore.

However, if the if line doesn't exceed the Prettier's printWidth, the expected result would be:

// Comment 1 and Comment 2
if (balanceOf(msg.sender) >= 1000) priority = true;

// Comment 3
else {
    // ...multi-line stuff here
}

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