Repository: prettier/prettier (JavaScript)

Issue:
Misaligned indent in curried arrow function
**Prettier 2.6.2**
[Playground link](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEwA6UAEn1ezjffSKAZxkwA9MBeTAQQDoAjACkKP3b0+NszQgAhszAATOADMA5gAsAlgCsA1gBsAtlAgAHAI4AncgFcAbgHdKATwBeI8VLlK1mnQePmrt0RMmCANBy82GL8gnY+jioaWnqGMKYWNuEOClEuse6JXva+IIGcAJS0AHz5RKxwRTTFmAAMZZgFANz5AL4c7VCdIH4gOjDy0KTIoEL6+hBmAApjCMMoQqpmQpbDvcz6QmDKcDAAykLqcAAy8lBwyJKLpHDrm9u7e9pbZ9LIMPpGtyBw6sxwYgkYmOQig0iMQmkcAAYhB9OohDABmDkMIjDAID0QLIYOpVAB1BTwUjPMBwPZzeQDExUyyosCkNYgM43fQwKabaQIy7Xb6KUiUPavVRwACKRgg8B5qhuvWehjg+lRMEs2jgpDA+nk2hgWO0Wtg+PkYhgsmQAEYAEy1OUTG74zbaVH69WKkwXXq6CXwDk6ebCUgAWnOAIBWP0cC98gjHMh3KQVxl3xu6nk70+yeFYu9FwTvN6MBERpNZqQloLm3kqleAGEIOp4z9SABWLFGG4AFRE80TspAJi+AEkoBJYHtNdqYPQR3sVSLpTdWq0gA)
<!-- prettier-ignore -->
```sh
--parser typescript
--print-width 120
```

**Input:**
<!-- prettier-ignore -->
```tsx
{
  {
    {
      const x = A.b(
        (
          c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
          d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
        ) =>
        (e) => 0
      );
    }
  }
}

```

**Output:**
<!-- prettier-ignore -->
```tsx
{
  {
    {
      const x = A.b(
        (
            c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
            d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
          ) =>
          (e) =>
            0
      );
    }
  }
}

```

**Expected behavior:**
Same as Input.


Hints:

Patch:
diff --git a/src/language-js/print/function.js b/src/language-js/print/function.js
--- a/src/language-js/print/function.js
+++ b/src/language-js/print/function.js
@@ -12,6 +12,7 @@ import {
   softline,
   group,
   indent,
+  dedent,
   ifBreak,
   hardline,
   join,
@@ -254,6 +255,10 @@ function printArrowChain(
 
   const groupId = Symbol("arrow-chain");
 
+  if ((isCallLikeExpression(parent) && !isCallee) || isBinaryish(parent)) {
+    signatures = [dedent(signatures[0]), ...signatures.slice(1)];
+  }
+
   // We handle sequence expressions as the body of arrows specially,
   // so that the required parentheses end up on their own lines.
   if (tailNode.body.type === "SequenceExpression") {


Test patch:
diff --git a/tests/format/js/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/arrows/__snapshots__/jsfmt.spec.js.snap
--- a/tests/format/js/arrows/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/arrows/__snapshots__/jsfmt.spec.js.snap
@@ -2062,6 +2062,240 @@ foo(
 ================================================================================
 `;
 
+exports[`chain-as-arg.js - {"arrowParens":"always"} format 1`] = `
+====================================options=====================================
+arrowParens: "always"
+parsers: ["babel", "typescript"]
+printWidth: 80
+                                                                                | printWidth
+=====================================input======================================
+const w = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+);
+
+const x = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+)(x);
+
+const y = a.b(
+  1,
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+)(x);
+
+const z = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0,
+  2
+)(x);
+
+
+=====================================output=====================================
+const w = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    (e) =>
+      0,
+);
+
+const x = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    (e) =>
+      0,
+)(x);
+
+const y = a.b(
+  1,
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    (e) =>
+      0,
+)(x);
+
+const z = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    (e) =>
+      0,
+  2,
+)(x);
+
+================================================================================
+`;
+
+exports[`chain-as-arg.js - {"arrowParens":"avoid"} format 1`] = `
+====================================options=====================================
+arrowParens: "avoid"
+parsers: ["babel", "typescript"]
+printWidth: 80
+                                                                                | printWidth
+=====================================input======================================
+const w = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+);
+
+const x = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+)(x);
+
+const y = a.b(
+  1,
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+)(x);
+
+const z = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0,
+  2
+)(x);
+
+
+=====================================output=====================================
+const w = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    e =>
+      0,
+);
+
+const x = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    e =>
+      0,
+)(x);
+
+const y = a.b(
+  1,
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    e =>
+      0,
+)(x);
+
+const z = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    e =>
+      0,
+  2,
+)(x);
+
+================================================================================
+`;
+
+exports[`chain-in-logical-expression.js - {"arrowParens":"always"} format 1`] = `
+====================================options=====================================
+arrowParens: "always"
+parsers: ["babel", "typescript"]
+printWidth: 80
+                                                                                | printWidth
+=====================================input======================================
+const x = a.b ?? (
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+);
+
+=====================================output=====================================
+const x =
+  a.b ??
+  ((
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    (e) =>
+      0);
+
+================================================================================
+`;
+
+exports[`chain-in-logical-expression.js - {"arrowParens":"avoid"} format 1`] = `
+====================================options=====================================
+arrowParens: "avoid"
+parsers: ["babel", "typescript"]
+printWidth: 80
+                                                                                | printWidth
+=====================================input======================================
+const x = a.b ?? (
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+);
+
+=====================================output=====================================
+const x =
+  a.b ??
+  ((
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+  ) =>
+    e =>
+      0);
+
+================================================================================
+`;
+
 exports[`comment.js - {"arrowParens":"always"} format 1`] = `
 ====================================options=====================================
 arrowParens: "always"
diff --git a/tests/format/js/arrows/chain-as-arg.js b/tests/format/js/arrows/chain-as-arg.js
new file mode 100644
--- /dev/null
+++ b/tests/format/js/arrows/chain-as-arg.js
@@ -0,0 +1,38 @@
+const w = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+);
+
+const x = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+)(x);
+
+const y = a.b(
+  1,
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+)(x);
+
+const z = a.b(
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0,
+  2
+)(x);
+
diff --git a/tests/format/js/arrows/chain-in-logical-expression.js b/tests/format/js/arrows/chain-in-logical-expression.js
new file mode 100644
--- /dev/null
+++ b/tests/format/js/arrows/chain-in-logical-expression.js
@@ -0,0 +1,8 @@
+const x = a.b ?? (
+  (
+    c = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef",
+    d = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"
+  ) =>
+  (e) =>
+    0
+);