dprint-plugin-typescript
dprint-plugin-typescript copied to clipboard
Multi-line arrow-function expression body should not add line break after arrow in certain circumstances
Describe the bug
dprint-plugin-typescript version: 0.40.1
Input Code
colors.map(color => darken({
color,
opacity: 1
}));
Expected Output
colors.map(color => darken({
color,
opacity: 1
}));
Actual Output
colors.map(color =>
darken({
color,
opacity: 1,
})
);
Adding a line break before the arrow makes a lot of code unnecessarily verbose with small expressions.
Thank you!
Another similar example from @declanvong:
https://dprint.dev/playground/#code/GYexAoDsFMHcAIDyAjAVuA3gKHr+BDALnlBABoc9ljl8AnCgXwEpmBuIA/language/typescript
foo(new Obj({
a: foo,
b: bar,
}));
Outputs:
foo(
new Obj({
a: foo,
b: bar,
}),
);
(I know these examples are different, but perhaps the implementation could use the same logic)
I agree with @WearyMonkey, arrow functions that return single expression should be able to be compacted as much as they can, the current behavior discourages the usage of higher order functions in cases like currying etc.:
const add = x => y => {
return x + y
}
becomes:
const add = x =>
y => {
return x + y;
}
which is less readable as the "y" is now in a different line than the "x" so harder to reason about.
my example:
const render = () => html`
<div b="1 rd-4 gray-300">
<button m-4 p-2 rd onclick="${addKid}">+</button>
</div>
`
(html shouldn't go on next line)
Did not find any config to change this behaviour