Prettier: not-so-pretty output, function call followed by operators

Created on 19 Jun 2017  路  3Comments  路  Source: prettier/prettier

Input, looks quite good imho

var angle = Math.floor(
    Math.atan2(
        entity.gridY - this.gridY,
        entity.gridX - this.gridX
    ) * 180 / Math.PI
);

Prettier Output

var angle = Math.floor(
    Math.atan2(entity.gridY - this.gridY, entity.gridX - this.gridX) *
        180 /
        Math.PI
);
locked-due-to-inactivity needs discussion

Most helpful comment

function toDegrees(radians) {
  return radians * 180 / Math.PI;
}

var dx = entity.gridX - this.gridX;
var dy = entity.gridY - this.gridY;
var angle = Math.floor(toDegrees(Math.atan2(dy, dx)));

All 3 comments

Agreed, the input looks better and the output worse. I'm not really sure how to fix it though. Prettier doesn't know how to print the first form and making it know about it would change a bunch of other things. I'll think about it but right now you'll have to live with it i'm afraid :(

function toDegrees(radians) {
  return radians * 180 / Math.PI;
}

var dx = entity.gridX - this.gridX;
var dy = entity.gridY - this.gridY;
var angle = Math.floor(toDegrees(Math.atan2(dy, dx)));

I'm going to close this since I don't really know how we can gracefully handle this case :(

Was this page helpful?
0 / 5 - 0 ratings