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

Better display of localVariableDeclarationStatement modifiers #283

Merged

Conversation

clementdessoude
Copy link
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

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
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

lppedd commented Oct 14, 2019

@clement26695 that's perfect imho.

@lppedd
Copy link

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
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