Subject: Re: bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements

From: Yuan Fu <[email-masked]>
Date: Mon, 27 Nov 2023 21:53:49 -0800

On 11/27/23 4:39 PM, Dmitry Gutov wrote:
> On 27/11/2023 19:07, Noah Peart wrote:
>> Tags: patch
>>
>> * lisp/progmodes/typescript-ts-mode.el(typescript-ts-mode): Add 
>> indentation
>> rule for switch case and default keywords.
>>
>> Bug: `typescript-ts-mode` is missing indentation rules for 'case' and
>> 'default' keywords in switch statements.
>>
>> Recipe to reproduce:
>> Copy the following code into a buffer:
>>
>>      const foo = (x: string) => {
>>        switch (x) {
>>                    case "a":
>>                    console.log(x);
>>                    return 1;
>>      case "b":
>>        return 2;
>>                    case "c":
>>                    default:
>>                      return 0;
>>        }
>>      };
>>
>> And call the following function to configure typescript-ts-mode and
>> indent the buffer
>>
>>      (defun my-ts-indentation ()
>>        (interactive)
>>        (setq indent-tabs-mode nil)
>>        (setq typescript-ts-mode-indent-offset 2)
>>        (typescript-ts-mode)
>>        (indent-region (point-min) (point-max)))
>>
>> The indentation for the 'case' and 'default' branches within the switch
>> statement should still be unchanged due to missing indent rules.
>> Bug applies to emacs 29 as well.
>
> Thanks! Can repro. The fix looks good as well.
>
LGTM. The only thing I'll add is that you can probably use a single 
regular expression rather than using the "or" matcher. But that's 
largely personal preference.

Yuan