Repository: prettier/prettier (JavaScript)
Date: 2018-10-08 18:08:59+00:00
Task type: Bug Fix

Issue:
Ternary causes arrow function as last arg indent
**Prettier 1.12.1**
[Playground link](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAPAdDAFggFAHSgAIjcBKIgXgD5CSSBDO+kgfiIDc4AnATwDUegvlz7DhvUQKE9Js8bIAy0AObMWSIgCMduvfoNaANITIBuQiCMgIABxgBLaAGdkoBt24QA7gAUPCK4oDBwQDgAmViBa3AxgANZwMADKtnEOUCrIMNwArnDWGc48ML6xKgC2DMgAZgwANsXWAFbOqABCsQlJyQwVcIoZcLUNTSBp3MXcyNEMWrz10FG23BkwAOoR2MgAHAAM1isQxeuxtjMrcFNcUdxwAI65DndlDJXVSHWNBSDFFQ7ZPI-ZwZFT1OAARVyEHgI2+1hgc024W2SAATAjYg56qCAMIQCpVGZQaDDay5YoAFTmQS+xQAvvSgA)

**Input:**
```jsx
x.then(() =>
  a
    ? veryVerVeryveryVerVeryveryVerVeryveryVerVeryLong
    : bbbbbbbbbbbbbbbbbbbbbb,
);

```

**Output:**
```jsx
x.then(
  () =>
    a
      ? veryVerVeryveryVerVeryveryVerVeryveryVerVeryLong
      : bbbbbbbbbbbbbbbbbbbbbb
);

```

**Expected behavior:**
```jsx
x.then(() =>
  a
    ? veryVerVeryveryVerVeryveryVerVeryveryVerVeryLong
    : bbbbbbbbbbbbbbbbbbbbbb
);

```

This happens for `||` as well, is it intentional?



Issue discussion:

Solution patch:
diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js
index 3c7713dc59ff..de768e495919 100644
--- a/src/language-js/printer-estree.js
+++ b/src/language-js/printer-estree.js
@@ -3400,6 +3400,7 @@ function couldGroupArg(arg) {
         arg.body.type === "ArrayExpression" ||
         arg.body.type === "CallExpression" ||
         arg.body.type === "OptionalCallExpression" ||
+        arg.body.type === "ConditionalExpression" ||
         isJSXNode(arg.body)))
   );
 }


Test patch:
diff --git a/tests/arrow-call/__snapshots__/jsfmt.spec.js.snap b/tests/arrow-call/__snapshots__/jsfmt.spec.js.snap
index d2b9b1a0aed3..7d7535f7a791 100644
--- a/tests/arrow-call/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/arrow-call/__snapshots__/jsfmt.spec.js.snap
@@ -1,6 +1,6 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`arrow_call.js - flow-verify 1`] = `
+exports[`arrow_call.js - babylon-verify 1`] = `
 const testResults = results.testResults.map(testResult =>
   formatResult(testResult, formatter, reporter)
 );
@@ -43,6 +43,8 @@ const composition = (ViewComponent, ContainerComponent) =>
   class extends React.Component {
     static propTypes = {};
   };
+
+promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 const testResults = results.testResults.map(testResult =>
   formatResult(testResult, formatter, reporter)
@@ -93,9 +95,15 @@ const composition = (ViewComponent, ContainerComponent) =>
     static propTypes = {};
   };
 
+promise.then(result =>
+  result.veryLongVariable.veryLongPropertyName > someOtherVariable
+    ? "ok"
+    : "fail"
+);
+
 `;
 
-exports[`arrow_call.js - flow-verify 2`] = `
+exports[`arrow_call.js - babylon-verify 2`] = `
 const testResults = results.testResults.map(testResult =>
   formatResult(testResult, formatter, reporter)
 );
@@ -138,6 +146,8 @@ const composition = (ViewComponent, ContainerComponent) =>
   class extends React.Component {
     static propTypes = {};
   };
+
+promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 const testResults = results.testResults.map(testResult =>
   formatResult(testResult, formatter, reporter),
@@ -188,9 +198,15 @@ const composition = (ViewComponent, ContainerComponent) =>
     static propTypes = {};
   };
 
+promise.then(result =>
+  result.veryLongVariable.veryLongPropertyName > someOtherVariable
+    ? "ok"
+    : "fail",
+);
+
 `;
 
-exports[`arrow_call.js - flow-verify 3`] = `
+exports[`arrow_call.js - babylon-verify 3`] = `
 const testResults = results.testResults.map(testResult =>
   formatResult(testResult, formatter, reporter)
 );
@@ -233,6 +249,8 @@ const composition = (ViewComponent, ContainerComponent) =>
   class extends React.Component {
     static propTypes = {};
   };
+
+promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 const testResults = results.testResults.map((testResult) =>
   formatResult(testResult, formatter, reporter)
@@ -283,4 +301,10 @@ const composition = (ViewComponent, ContainerComponent) =>
     static propTypes = {};
   };
 
+promise.then((result) =>
+  result.veryLongVariable.veryLongPropertyName > someOtherVariable
+    ? "ok"
+    : "fail"
+);
+
 `;
diff --git a/tests/arrow-call/arrow_call.js b/tests/arrow-call/arrow_call.js
index cb73bf52f184..536ad9e57f1f 100644
--- a/tests/arrow-call/arrow_call.js
+++ b/tests/arrow-call/arrow_call.js
@@ -40,3 +40,5 @@ const composition = (ViewComponent, ContainerComponent) =>
   class extends React.Component {
     static propTypes = {};
   };
+
+promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
diff --git a/tests/arrow-call/jsfmt.spec.js b/tests/arrow-call/jsfmt.spec.js
index 6929f9c24ffd..93724d9bec31 100644
--- a/tests/arrow-call/jsfmt.spec.js
+++ b/tests/arrow-call/jsfmt.spec.js
@@ -1,3 +1,7 @@
-run_spec(__dirname, ["flow", "typescript"]);
-run_spec(__dirname, ["flow", "typescript"], { trailingComma: "all" });
-run_spec(__dirname, ["flow", "typescript"], { arrowParens: "always" });
+run_spec(__dirname, ["babylon", "flow", "typescript"]);
+run_spec(__dirname, ["babylon", "flow", "typescript"], {
+  trailingComma: "all"
+});
+run_spec(__dirname, ["babylon", "flow", "typescript"], {
+  arrowParens: "always"
+});
diff --git a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap
index eb4f931d2afd..e215d0863d08 100644
--- a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap
@@ -22,14 +22,13 @@ const funnelSnapshotCard =
   ) : null;
 
 room = room.map((row, rowIndex) =>
-  row.map(
-    (col, colIndex) =>
-      rowIndex === 0 ||
-      colIndex === 0 ||
-      rowIndex === height ||
-      colIndex === width
-        ? 1
-        : 0
+  row.map((col, colIndex) =>
+    rowIndex === 0 ||
+    colIndex === 0 ||
+    rowIndex === height ||
+    colIndex === width
+      ? 1
+      : 0
   )
 );
 
@@ -57,14 +56,13 @@ const funnelSnapshotCard =
     ) : null;
 
 room = room.map((row, rowIndex) =>
-    row.map(
-        (col, colIndex) =>
-            rowIndex === 0 ||
-            colIndex === 0 ||
-            rowIndex === height ||
-            colIndex === width
-                ? 1
-                : 0
+    row.map((col, colIndex) =>
+        rowIndex === 0 ||
+        colIndex === 0 ||
+        rowIndex === height ||
+        colIndex === width
+            ? 1
+            : 0
     )
 );
 
@@ -92,14 +90,13 @@ const funnelSnapshotCard =
 	) : null;
 
 room = room.map((row, rowIndex) =>
-	row.map(
-		(col, colIndex) =>
-			rowIndex === 0 ||
-			colIndex === 0 ||
-			rowIndex === height ||
-			colIndex === width
-				? 1
-				: 0
+	row.map((col, colIndex) =>
+		rowIndex === 0 ||
+		colIndex === 0 ||
+		rowIndex === height ||
+		colIndex === width
+			? 1
+			: 0
 	)
 );
 
@@ -127,14 +124,13 @@ const funnelSnapshotCard =
 	) : null;
 
 room = room.map((row, rowIndex) =>
-	row.map(
-		(col, colIndex) =>
-			rowIndex === 0 ||
-			colIndex === 0 ||
-			rowIndex === height ||
-			colIndex === width
-				? 1
-				: 0
+	row.map((col, colIndex) =>
+		rowIndex === 0 ||
+		colIndex === 0 ||
+		rowIndex === height ||
+		colIndex === width
+			? 1
+			: 0
 	)
 );