Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Function and class expression assignment #2417

Closed
Tracked by #2403
MichaReiser opened this issue Apr 13, 2022 · 2 comments
Closed
Tracked by #2403

Function and class expression assignment #2417

MichaReiser opened this issue Apr 13, 2022 · 2 comments
Assignees
Labels
A-Formatter Area: formatter I-Difficult Implementation: requires deep knowledge of the tools and the problem.

Comments

@MichaReiser
Copy link
Contributor

MichaReiser commented Apr 13, 2022

Rome breaks any function or class expression assignment over at least two lines if their bodies aren't empty. Prettier formats them on a single line (as one would expect). Playground

Input

// Assigning to function/classes with an empty yields the desired formatting
a = function() {}
a = class {}

// Assigning to a function/class with a non-empty body groups the whole assignment expression.
a = function () {
  console.log(1)
};

extraLongLeftHandSideLetsSeeHowPrettierBreaksThatAcrossMultipleLinesStillNotLongEnoughMustBeLongerAndLora = function () {
  console.log(1)
};

a = function extraLongLeftHandSideLetsSeeHowPrettierBreaksThatAcrossMultipleLinesStillNotLongEnoughMustBeLongerAndara () {
  console.log(1)
};

a = class {
  prop;
}

// Function with non-empty body is printed on the next line
A.prototype.f = function() {
  console.log(1)
}

Prettier

// Assigning to function/classes with an empty yields the desired formatting
a = function () {};
a = class {};

// Assigning to a function/class with a non-empty body groups the whole assignment expression.
a = function () {
  console.log(1);
};

extraLongLeftHandSideLetsSeeHowPrettierBreaksThatAcrossMultipleLinesStillNotLongEnoughMustBeLongerAndLora =
  function () {
    console.log(1);
  };

a =
  function extraLongLeftHandSideLetsSeeHowPrettierBreaksThatAcrossMultipleLinesStillNotLongEnoughMustBeLongerAndara() {
    console.log(1);
  };

a = class {
  prop;
};

// Function with non-empty body is printed on the next line
A.prototype.f = function () {
  console.log(1);
};

Rome

// Assigning to function/classes with an empty yields the desired formatting
a = function () {};
a = class {};

// Assigning to a function/class with a non-empty body groups the whole assignment expression.
a =
  function () {
    console.log(1);
  };

extraLongLeftHandSideLetsSeeHowPrettierBreaksThatAcrossMultipleLinesStillNotLongEnoughMustBeLongerAndLora =
  function () {
    console.log(1);
  };

a =
  function extraLongLeftHandSideLetsSeeHowPrettierBreaksThatAcrossMultipleLinesStillNotLongEnoughMustBeLongerAndara() {
    console.log(1);
  };

a =
  class {
    prop;
  };

// Function with non-empty body is printed on the next line
A.prototype.f =
  function () {
    console.log(1);
  };

Expected

Rome formats class and function expressions on a single line if there name fits on a single line.

@MichaReiser MichaReiser added the A-Formatter Area: formatter label Apr 13, 2022
@ematipico ematipico self-assigned this Apr 13, 2022
@ematipico ematipico added I-Normal Implementation: normal understanding of the tool and awareness I-Difficult Implementation: requires deep knowledge of the tools and the problem. and removed I-Normal Implementation: normal understanding of the tool and awareness labels May 5, 2022
@MichaReiser
Copy link
Contributor Author

I'm currently looking into formatting classes that should help with this.

@ematipico
Copy link
Contributor

This is now solved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter I-Difficult Implementation: requires deep knowledge of the tools and the problem.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants