Prettier: case of poor assignment layout

Created on 18 Jun 2017  Â·  3Comments  Â·  Source: prettier/prettier

This nice-ish code:

const areaPercentageDiff = (
    topRankedZoneFit.areaPercentageRemaining
  - previousZoneFitNow.areaPercentageRemaining
).toFixed(2)

gets formatted into uglier code:

const areaPercentageDiff = (topRankedZoneFit.areaPercentageRemaining -
  previousZoneFitNow.areaPercentageRemaining).toFixed(2);
javascript locked-due-to-inactivity bug

Most helpful comment

This now prints as:

Prettier 1.9.1
Playground link

Input:

const areaPercentageDiff = (
    topRankedZoneFit.areaPercentageRemaining
  - previousZoneFitNow.areaPercentageRemaining
).toFixed(2)

Output:

const areaPercentageDiff = (
  topRankedZoneFit.areaPercentageRemaining -
  previousZoneFitNow.areaPercentageRemaining
).toFixed(2);

Which is pretty similar to the input, except for where the - sign stays (end of line / start of next line) but I guess the primary issue was fixed.. if anyone dislikes the - placement, please open a new issue :-)

All 3 comments

FTR this is now printing:

const areaPercentageDiff = (topRankedZoneFit.areaPercentageRemaining -
  previousZoneFitNow.areaPercentageRemaining
).toFixed(2);

Related to #2775. This matches the logical expression case:

const foo = (bar &&
  baz
).call()

This now prints as:

Prettier 1.9.1
Playground link

Input:

const areaPercentageDiff = (
    topRankedZoneFit.areaPercentageRemaining
  - previousZoneFitNow.areaPercentageRemaining
).toFixed(2)

Output:

const areaPercentageDiff = (
  topRankedZoneFit.areaPercentageRemaining -
  previousZoneFitNow.areaPercentageRemaining
).toFixed(2);

Which is pretty similar to the input, except for where the - sign stays (end of line / start of next line) but I guess the primary issue was fixed.. if anyone dislikes the - placement, please open a new issue :-)

Was this page helpful?
0 / 5 - 0 ratings