Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: break long lines on type arguments #584

Merged

Conversation

jtkiesel
Copy link
Contributor

@jtkiesel jtkiesel commented Jul 9, 2023

What changed with this PR:

Long lines containing type arguments (i.e. those that previously violated printWidth) are now broken on type arguments the way Prettier JavaScript does (on TypeScript).

Example

Input

class Example {

  <A extends ShortClassName & ShortClassName & ShortClassName & ShortClassName, B extends ShortClassName & ShortClassName & ShortClassName & ShortClassName & ShortClassName, C extends ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName> & ExtremelyLongAndObnoxiousInterfaceName & ExtremelyLongAndObnoxiousInterfaceName & ExtremelyLongAndObnoxiousInterfaceName> void example(
    ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName> parameter,
    ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName> parameter
  ) {
    ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName> variable;

    ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName> variable;

    ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName> variable =
      new MyExtremelyLongAndObnoxiousClassName<>();

    ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName> variable =
      new MyExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName>();

    ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName> aParticularlyLongAndObnoxiousNameForIllustrativePurposes =
      new MyExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName>();

    new MyExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName<ExtremelyLongAndObnoxiousClassName, ExtremelyLongAndObnoxiousClassName>, ExtremelyLongAndObnoxiousClassName>()
      .method();
  }
}

Output

class Example {

  <
    A extends ShortClassName & ShortClassName & ShortClassName & ShortClassName,
    B extends ShortClassName
      & ShortClassName
      & ShortClassName
      & ShortClassName
      & ShortClassName,
    C extends ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    >
      & ExtremelyLongAndObnoxiousInterfaceName
      & ExtremelyLongAndObnoxiousInterfaceName
      & ExtremelyLongAndObnoxiousInterfaceName
  > void example(
    ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName
    > parameter,
    ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    > parameter
  ) {
    ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName
    > variable;

    ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    > variable;

    ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    > variable = new MyExtremelyLongAndObnoxiousClassName<>();

    ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    > variable = new MyExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    >();

    ExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    > aParticularlyLongAndObnoxiousNameForIllustrativePurposes =
      new MyExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName<
          ExtremelyLongAndObnoxiousClassName,
          ExtremelyLongAndObnoxiousClassName
        >,
        ExtremelyLongAndObnoxiousClassName
      >();

    new MyExtremelyLongAndObnoxiousClassName<
      ExtremelyLongAndObnoxiousClassName<
        ExtremelyLongAndObnoxiousClassName,
        ExtremelyLongAndObnoxiousClassName
      >,
      ExtremelyLongAndObnoxiousClassName
    >()
      .method();
  }
}

Relative issues or prs:

None

@jtkiesel jtkiesel force-pushed the feat/break-on-type-arguments branch from 2c6b86c to b946ef0 Compare July 9, 2023 07:49
@jtkiesel jtkiesel force-pushed the feat/break-on-type-arguments branch from b946ef0 to 8764988 Compare July 10, 2023 07:48
@jtkiesel jtkiesel changed the title feat: break long variable declarations/assignments on type arguments feat: break long lines on type arguments Jul 10, 2023
@clementdessoude
Copy link
Contributor

LGTM ! Thanks @jtkiesel !

@clementdessoude clementdessoude merged commit 20da8ea into jhipster:main Jul 22, 2023
@jtkiesel jtkiesel deleted the feat/break-on-type-arguments branch July 22, 2023 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants