jhipster / prettier-java

Prettier Java Plugin
http://www.jhipster.tech/prettier-java/
Apache License 2.0
1.06k stars 103 forks source link

feat: adjust text block indentation #596

Closed jtkiesel closed 10 months ago

jtkiesel commented 11 months ago

What changed with this PR:

Text blocks are now split by lines when printing, with the "base indentation" removed, so that they are indented more logically by Prettier.

Example

Input

class Example {

  void example() {
    System.out.println(
      // leading comment
        """
               abaoeu
                 euaoeu
              aoeu

               oaeu
                    abc""" // trailing comment
    );

    System.out.println(
        """
 abaoeu
   euaoeu
aoeu

 oaeu
      abc"""
    );
  }
}

Output

class Example {

  void example() {
    System.out.println(
      // leading comment
      """
       abaoeu
         euaoeu
      aoeu

       oaeu
            abc""" // trailing comment
    );

    System.out.println(
      """
       abaoeu
         euaoeu
      aoeu

       oaeu
            abc"""
    );
  }
}

Relative issues or prs:

Closes #593

clementdessoude commented 10 months ago

Thanks again @jtkiesel ! I just have one comment, but the logic seems ok otherwise :)

jtkiesel commented 10 months ago

@DanielFran Bounty claimed: https://opencollective.com/generator-jhipster/expenses/155942

DanielFran commented 10 months ago

@jtkiesel approved