Skip to content

comment in function chain causes function to be wrapped in () with an extra space #3648

Closed

Description

@theverything

Prettier 1.9.2
Playground link

Input:

func1(function() {
  return func2
      //comment
      .bar();
});

Output:

func1(function() {
  return (func2
      //comment
      .bar() );
});

Expected behavior:

I wouldn't think it would wrap the function chain in () and at the least the extra space at the end wouldn't be necessary.

Activity

  1. hawkrives commented on Jan 4, 2018

    @hawkrives
    Contributor

    To add to this interesting bug, if that function is a top-level function, the return value gets wrapped in parens and expanded (as I'd expect the OP to do, too.) playground

    function x() {
      return func2
          //comment
          .bar();
    };
    function x() {
      return (
        func2
          //comment
          .bar()
      );
    }
  2. duailibe commented on Jan 6, 2018

    @duailibe
    Collaborator

    I suspect this is another case of removeLines:

    // If the parent is a call with the first/last argument expansion and this is the
    // params of the first/last argument, we dont want the arguments to break and instead
    // want the whole expression to be on a new line.
    //
    // Good: Bad:
    // verylongcall( verylongcall((
    // (a, b) => { a,
    // } b,
    // }) ) => {
    // })
    if (
    expandArg &&
    !(fun[paramsField] && fun[paramsField].some(n => n.comments))
    ) {
    return group(
    concat([
    docUtils.removeLines(typeParams),
    "(",
    join(", ", printed.map(docUtils.removeLines)),
    ")"
    ])
    );
    }

    can't confirm right now

    EDIT: it's not that, investigating

  3. self-assigned this
    on Jan 7, 2018
  4. added
    status:has pr
    on Jan 7, 2018
  5. added
    locked-due-to-inactivity
    on Jul 6, 2018
  6. locked as resolved and limited conversation to collaborators on Jul 6, 2018
  7. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

lang:javascriptlocked-due-to-inactivitystatus:has pr

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions