Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-line arrow-function expression body should not add line break after arrow in certain circumstances #107

Open
WearyMonkey opened this issue Feb 20, 2021 · 3 comments · May be fixed by #528
Labels
enhancement New feature or request

Comments

@WearyMonkey
Copy link

WearyMonkey commented Feb 20, 2021

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,
  })
);

Playground link

Adding a line break before the arrow makes a lot of code unnecessarily verbose with small expressions.

Thank you!

@WearyMonkey WearyMonkey changed the title Multi-line arrow-function expression body should maintain absence or presence of line break after arrow. Multi-line arrow-function expression body should not add line break after arrow. Feb 20, 2021
@dsherret dsherret added the enhancement New feature or request label Mar 20, 2021
@dsherret dsherret changed the title Multi-line arrow-function expression body should not add line break after arrow. Multi-line arrow-function expression body should not add line break after arrow in certain circumstances Mar 20, 2021
@dsherret
Copy link
Member

dsherret commented Sep 30, 2021

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)

@stagas
Copy link
Contributor

stagas commented Mar 23, 2022

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.

Ty3uK added a commit to Ty3uK/dprint-plugin-typescript that referenced this issue May 25, 2023
Resolves dprint#107.

If set to true dprint will not format this:

```typescript
[].map(() => test({
    foo: 1,
    bar: 2,
}));
````

to this:

```typescript
[].map(() =>
    test({
        foo: 1,
        bar: 2,
    })
);
```
@Ty3uK Ty3uK linked a pull request May 25, 2023 that will close this issue
Ty3uK added a commit to Ty3uK/dprint-plugin-typescript that referenced this issue May 26, 2023
Resolves dprint#107.

If set to true dprint will not format this:

```typescript
[].map(() => test({
    foo: 1,
    bar: 2,
}));
````

to this:

```typescript
[].map(() =>
    test({
        foo: 1,
        bar: 2,
    })
);
```
Ty3uK added a commit to Ty3uK/dprint-plugin-typescript that referenced this issue May 26, 2023
Resolves dprint#107.

If set to true dprint will not format this:

```typescript
[].map(() => test({
    foo: 1,
    bar: 2,
}));
````

to this:

```typescript
[].map(() =>
    test({
        foo: 1,
        bar: 2,
    })
);
```
@tennox
Copy link

tennox commented Jun 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants