Skip to content

Better display of localVariableDeclarationStatement modifiers#283

Merged
clementdessoude merged 1 commit intojhipster:masterfrom
clementdessoude:fix/localVariableDeclaration
Oct 15, 2019
Merged

Better display of localVariableDeclarationStatement modifiers#283
clementdessoude merged 1 commit intojhipster:masterfrom
clementdessoude:fix/localVariableDeclaration

Conversation

@clementdessoude
Copy link
Copy Markdown
Contributor

Fix #282

@lppedd, this would now be formatted like this:

public boolean localVariableDeclarationWhichBreak() {
    @Nullable
    final BackupStatus lastStatus = BackupStatus.fromDbValue(
      backupRepository.getLastStatus()
    );

    final BackupStatus lastStatus = BackupStatus.fromDbValue(
      backupRepository.getLastStatus()
    );

    @Nullable
    BackupStatus lastStatus = BackupStatus.fromDbValue(
      backupRepository.getLastStatus()
    );

    BackupStatus lastStatus = BackupStatus.fromDbValue(
      backupRepository.getLastStatus()
    );
  }

  public boolean localVariableDeclarationWhichDoNotBreak() {
    @Nullable
    final BackupStatus lastStatus = value;

    final BackupStatus lastStatus = value;

    @Nullable
    BackupStatus lastStatus = value;

    BackupStatus lastStatus = value;
  }

@lppedd
Copy link
Copy Markdown

lppedd commented Oct 14, 2019

@clement26695 thank you!
A question: what about this case? How would it become?

public boolean localVariableDeclarationWhichBreak() {
    @Nullable
    final BackupStatus lastStatus = BackupStatus.fromDbValue(      | print width
      backupRepository.aVeryLongFunctionNameWhichGoesOverThePrintWidth(myParam)
    );
    ...

@clementdessoude
Copy link
Copy Markdown
Contributor Author

clementdessoude commented Oct 14, 2019

This

class CLassWithEnum {

  public boolean localVariableDeclarationWhichBreak() {
    @Nullable
    final BackupStatus lastStatus = BackupStatus.fromDbValue(backupRepository.aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFunctionNameWhichGoesOverThePrintWidth(myParam));
    final BackupStatus lastStatus = BackupStatus.fromDbValue(backupRepository.aVeryLongFunctionNameWhichGoesOverThePrintWidth(myParam, myParam, myParam, myParam, myParam, myParam));
  }

}

would be printed like this:

class CLassWithEnum {

  public boolean localVariableDeclarationWhichBreak() {
    @Nullable
    final BackupStatus lastStatus = BackupStatus.fromDbValue(
      backupRepository.aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFunctionNameWhichGoesOverThePrintWidth(
        myParam
      )
    );
    final BackupStatus lastStatus = BackupStatus.fromDbValue(
      backupRepository.aVeryLongFunctionNameWhichGoesOverThePrintWidth(
        myParam,
        myParam,
        myParam,
        myParam,
        myParam,
        myParam
      )
    );
  }
}

@lppedd
Copy link
Copy Markdown

lppedd commented Oct 14, 2019

@clement26695 that's perfect imho.

@lppedd
Copy link
Copy Markdown

lppedd commented Oct 15, 2019

@clement26695 morning! Maybe a bit OT, but I wanted to know your opinion.
Take for example this class level constant

                                                                               | print witdh
private static final Logger logger = LoggerFactory.getLogger(BackupApiDelegateImpl.class);

How would you see it formatted? Like the local variable above? Because that's how it is now.

private static final Logger logger = LoggerFactory.getLogger(
  BackupApiDelegateImpl.class
);

Honestly I'd say something like

private static final Logger logger = 
  LoggerFactory.getLogger(BackupApiDelegateImpl.class);

Looks much more clear on the eye.

And in case of nested expressions, it would become

private static final Logger logger = 
  LoggerFactory.getLogger(
    SomethingElse.myExtremelyLongMethodNameWhichGoesOverPrint()
  );

private static final Logger logger = 
  LoggerFactory.getLogger(
    SomethingElse.myExtremelyLongMethodNameWhichGoesOverPrint(
      myParam1,
      myParam2
    )
  );

Btw, your changes works fine, I'm already using them.

@clementdessoude
Copy link
Copy Markdown
Contributor Author

FYI, I tried to improve this behavior in #255. I tried to be close to the Prettier JS behavior.

@clementdessoude clementdessoude merged commit bd2dc66 into jhipster:master Oct 15, 2019
@clementdessoude clementdessoude deleted the fix/localVariableDeclaration branch October 15, 2019 13:09
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.

final keyword should stay on the same line

3 participants