dprint-plugin-typescript icon indicating copy to clipboard operation
dprint-plugin-typescript copied to clipboard

linePerExpression adds incorrect newlines sometimes

Open bitnimble opened this issue 2 years ago • 1 comments

Describe the bug

A config with "preferSingleLine": "true" and "memberExpression.linePerExpression": "true" can sometimes line break incorrectly at places where there definitely shouldn't be a line break.

I haven't debugged this yet but I have a fairly minimal reproduction case -- unfortunately it looks like it's context dependent, based on the line lengths of previous lines... so might be a bit of an annoying one. I'm guessing that it's similar to other incorrect-newline cases in the past and it's just reusing a saved condition result. Probably the preferSingleLine is leading to a prior line getting collapsed which exceeds the line limit.

Playground link: here

dprint-plugin-typescript version: 0.65.1

Input Code

function a() {
    // Add a single character after "SomethingFairlyLong" to see it break
    AFunction(new SomethingFairlyLong1(
        'somethingreallylong',
        async (variable: string) => {
            if (!result.success) {
            }
            const v = result.value;
        },
    ));
}

Expected Output

function a() {
    // Add a single character after "SomethingFairlyLong" to see it break
    AFunction(
        new SomethingFairlyLong1(
            "somethingreallylong",
            async (variable: string) => {
                if (!result.success) {
                }
                const v = result.value;
            },
        ),
    );
}

Actual Output

function a() {
    // Add a single character after "SomethingFairlyLong" to see it break
    AFunction(
        new SomethingFairlyLong1(
            "somethingreallylong",
            async (variable: string) => {
                if (!result.success) {
                }
                const v = result
                    .value;
            },
        ),
    );
}

(result.value is broken up)

bitnimble avatar Mar 25 '22 00:03 bitnimble

This no longer happens on 0.79.0, so it seems like it has been fixed. @dsherret we can close this one for now unless it pops its head up again.

declanvong avatar Dec 21 '22 11:12 declanvong