GNU bug report logs - #68054
[PATCH] Add tree-sitter indent rule for lexical decls in js/typescript

Previous Next

Package: emacs;

Reported by: Noah Peart <noah.v.peart <at> gmail.com>

Date: Wed, 27 Dec 2023 06:22:01 UTC

Severity: wishlist

Tags: patch

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Noah Peart <noah.v.peart <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls in js/typescript
Date: Tue, 23 Apr 2024 19:36:45 -0700
[Message part 1 (text/plain, inline)]
> What js-mode does (looks like 3) shouldn't be too bad, but I wouldn't
mind an extra indentation level for such cases, too (example 2).

The problem I found with option 2/3 was cases like the following (which
also seem like the most common) where I expect the start of
the function be indented according to `typescript-ts-mode-indent-offset`,
not with the declaration keyword "const" as in `js-mode` (and option 3).

    const someFuncWithReallyLongName =
      async (x: number, y: number, z: number): Promise<void> => {
        // ...
      };

> This seems like a rare enough case, so it probably doesn't matter too
much, so I'd suggest picking one style and implementing it, and then
adjusting based on user feedback later.

I've attached a patch implementing option 1 for now (with a test), but
I'm happy to change the style whenever.

Thanks!

On Tue, Apr 23, 2024 at 5:15 PM Dmitry Gutov <dmitry <at> gutov.dev> wrote:

> On 23/04/2024 08:07, Yuan Fu wrote:
> >> 1) indent the dangling values with respect to start of the declaration
> >>
> >>      const a =
> >>          (x: string): string => {
> >>              return x + x;
> >>          },
> >>            bbb =
> >>          {
> >>              "x": 0
> >>          },
> >>            cccc =
> >>          1,
> >>            ddddd = 0;
> >>
> >> 2) indent them with respect to the start of the variable_declarator
> >>
> >>      const a =
> >>                (x: string): string => {
> >>                    return x + x;
> >>                },
> >>            bbb =
> >>                {
> >>                    "x": 0
> >>                },
> >>            cccc =
> >>                1,
> >>            ddddd = 0;
> >>
> >> 3) align with the variable declarators (this is the same as js-mode)
> >>
> >>      const a =
> >>            (x: string): string => {
> >>                return x + x;
> >>            },
> >>            bbb =
> >>            {
> >>                "x": 0
> >>            },
> >>            cccc =
> >>            1,
> >>            ddddd = 0;
> >>
> >> I've attached a patch with with the rules for the 3 options here.
> > I don’t really know what’s the convention, if there is one. Maybe Dmitry
> has better idea. Personally I like option 1.
>
> What js-mode does (looks like 3) shouldn't be too bad, but I wouldn't
> mind an extra indentation level for such cases, too (example 2).
>
> This seems like a rare enough case, so it probably doesn't matter too
> much, so I'd suggest picking one style and implementing it, and then
> adjusting based on user feedback later.
>
[Message part 2 (text/html, inline)]
[0001-Add-typescript-ts-mode-indentation-for-multi-assignm.patch (text/x-patch, attachment)]

This bug report was last modified 191 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.