dprint-plugin-typescript
dprint-plugin-typescript copied to clipboard
linePerExpression adds incorrect newlines sometimes
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)
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.