Subject: bug#78121: closed (Re: bug#78121: tsx-ts-mode: wrong indentation of body with misindented args)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 26 May 2025 03:54:02 +0000

Your bug report

#78121: tsx-ts-mode: wrong indentation of body with misindented args

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
78121: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78121
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#78121: tsx-ts-mode: wrong indentation of body with misindented args
From: Yuan Fu <[email-masked]>
To: Konstantin Kharlamov <[email-masked]>
Cc: Eli Zaretskii <[email-masked]>, [email-masked]
Date: Sun, 25 May 2025 20:53:13 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

> On May 25, 2025, at 2:03 AM, Konstantin Kharlamov <[email-masked]> wrote:
> 
> On Sun, 2025-05-25 at 11:55 +0300, Eli Zaretskii wrote:
>>> Cc: [email-masked]
>>> From: Konstantin Kharlamov <[email-masked]>
>>> Date: Sun, 25 May 2025 11:36:31 +0300
>>> 
>>> v5: I noticed I forgot to add the "*" bullets to the commit
>>> message,
>>> fixed.
>> 
>> Thanks, but if we are talking about formatting of the log messages,
>> then these ones have too long lines.  When we generate ChangeLog
>> files
>> from Git log, the log messages are indented 8 columns, so the longest
>> line should be 70 columns, and preferably 63.
> 
> Thanks, done (v6 attached)!
From 338b7610d9819f471ba58e86119c7fc03207d7a1 Mon Sep 17 00:00:00 2001
From: Konstantin Kharlamov <[email-masked]>
Date: Tue, 29 Apr 2025 21:51:18 +0700
Subject: [PATCH] typescript-ts: don't misindent body if params are misaligned
 (bug#78121)

Older code was calculating body indentation depending on function
parameters alignment.  This is incorrect, because if parameters are
misaligned, so will the function body.  Instead, use offset of the
previous standalone parent.

* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--indent-rules): Stop depending on function
parameters indentation for calculating body content and the closing
`}'.
* test/lisp/progmodes/typescript-ts-mode-resources/indent.erts:
(Function body with params misindented (bug#78121)): Add new test.
---
 lisp/progmodes/typescript-ts-mode.el          |  4 +--
 .../typescript-ts-mode-resources/indent.erts  | 25 +++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 24953f629de..6f807c254bd 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -155,7 +155,7 @@ typescript-ts-mode--indent-rules
   (typescript-ts-mode--check-dialect language)
   `((,language
      ((parent-is "program") column-0 0)
-     ((node-is "}") parent-bol 0)
+     ((node-is "}") standalone-parent 0)
      ((node-is ")") parent-bol 0)
      ((node-is "]") parent-bol 0)
      ((node-is ">") parent-bol 0)
@@ -165,7 +165,7 @@ typescript-ts-mode--indent-rules
      ((parent-is "ternary_expression") standalone-parent typescript-ts-mode-indent-offset)
      ((parent-is "member_expression") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "named_imports") parent-bol typescript-ts-mode-indent-offset)
-     ((parent-is "statement_block") parent-bol typescript-ts-mode-indent-offset)
+     ((parent-is "statement_block") standalone-parent typescript-ts-mode-indent-offset)
      ((or (node-is "case")
           (node-is "default"))
       parent-bol typescript-ts-mode-indent-offset)
diff --git a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
index e8b1d57f132..210bfcabd41 100644
--- a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
@@ -182,3 +182,28 @@ interface Foo {
   bar?: boolean;
 }
 =-=-=
+
+Code:
+  (lambda ()
+    (setq tsx-ts-mode-indent-offset 2)
+    (tsx-ts-mode)
+    (setq indent-tabs-mode nil)
+    (indent-region (line-beginning-position 7) (point-max)))
+
+Name: Function body with params misindented (bug#78121)
+
+=-=
+const f1 = (a1: string,
+            a2: number) => {
+    const f2 = (a1: string,
+                a2: number) => {
+      const f3 = (a1: string,
+                  a2: number) =>
+        {
+          return;
+        }
+      return;
+    }
+  return;
+}
+=-=-=
-- 
2.49.0

Thank you! Merged to emacs-30.

Yuan

Subject: tsx-ts-mode: wrong indentation of body with misindented args
From: Konstantin Kharlamov <[email-masked]>
To: [email-masked]
Date: Mon, 28 Apr 2025 23:15:35 +0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Given this TypeScript:

    const updatePage = (a1: string,
                        a2: number) => {
      return true;
    }

upon attempting to indent the `return true;` line it becomes indented as:

    const updatePage = (a1: string,
                        a2: number) => {
                          return true;
    }

which isn't expected.

P.S.: I'd note separately that a2 gets indented to 2 spaces, which even though goes in line with VSCode, I am not sure if it's useful. Does anybody even indent the second param to "2 spaces" when 1st param resides much further align-wise? C and C++ modes align 2-nd param to the 1st one, python-mode does too. Should perhaps tsx-ts-mode handle that similarly as well?