Skip to content

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

Closed

Description

@WearyMonkey

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!

Activity

  1. 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.[/+] on Feb 20, 2021
  2. 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[/+] on Mar 20, 2021
  3. dsherret commented on Sep 30, 2021

    @dsherret
    Member

    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)

  4. stagas commented on Mar 23, 2022

    @stagas
    Contributor

    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.

  5. added 3 commits that reference this issue on May 25, 2023
    f611613
    26fafef
    cb89919
  6. tennox commented on Jun 11, 2023

    @tennox

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions