From 00e5014e004953381d83e546f3938520d031be8a Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 15 Feb 2017 20:00:02 -0800 Subject: [PATCH] Align boolean inside of arrow functions (#691) We already do it for if/... but it looks weird for arrow function body. --- src/printer.js | 5 +++-- .../__snapshots__/jsfmt.spec.js.snap | 19 +++++++++++++++++++ tests/binary-expressions/arrow.js | 5 +++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/binary-expressions/arrow.js diff --git a/src/printer.js b/src/printer.js index 895ef4c7..b0d796eb 100644 --- a/src/printer.js +++ b/src/printer.js @@ -186,11 +186,12 @@ function genericPrintNoParens(path, options, print) { // Avoid indenting sub-expressions in if/etc statements. if ( shouldInlineLogicalExpression(n) || + n !== parent.body && (parent.type === "IfStatement" || parent.type === "WhileStatement" || parent.type === "DoStatement" || - parent.type === "ForStatement") && - n !== parent.body + parent.type === "ForStatement") || + n === parent.body && parent.type === "ArrowFunctionExpression" ) { return group(concat(parts)); } diff --git a/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap b/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap index 5ce0e6c9..a836415f 100644 --- a/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binary-expressions/__snapshots__/jsfmt.spec.js.snap @@ -1,3 +1,22 @@ +exports[`test arrow.js 1`] = ` +"function f() { + const appEntitys = getAppEntitys(loadObject).filter( + entity => entity && entity.isInstallAvailable() && !entity.isQueue() && entity.isDisabled() + ) +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function f() { + const appEntitys = getAppEntitys(loadObject).filter( + entity => + entity && + entity.isInstallAvailable() && + !entity.isQueue() && + entity.isDisabled() + ); +} +" +`; + exports[`test inline-object-array.js 1`] = ` "prevState = prevState || { catalogs: [], diff --git a/tests/binary-expressions/arrow.js b/tests/binary-expressions/arrow.js new file mode 100644 index 00000000..2fbafa9f --- /dev/null +++ b/tests/binary-expressions/arrow.js @@ -0,0 +1,5 @@ +function f() { + const appEntitys = getAppEntitys(loadObject).filter( + entity => entity && entity.isInstallAvailable() && !entity.isQueue() && entity.isDisabled() + ) +}