question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

format differences with PrettierJS

See original GitHub issue

We want to stay as close as possible to the reformatting style of Prettier JS

Below are some examples that should be reviewed:

  • TODO
var databaseSizeBeforeCreate = userRepository.findAll().collectList().block().size();
// PrettierJS =>
var databaseSizeBeforeCreate = userRepository
  .findAll()
  .collectList()
  .block()
  .size();
// Prettier-Java =>
var databaseSizeBeforeCreate = userRepository.findAll()
  .collectList()
  .block()
  .size();
  • TODO
var LONGER_LONGER_LONGER_LONGER_LONGER_LOCALE_REQUEST_ATTRIBUTE_NAME = AngularCookieLocaleContextResolver.class.getName() + ".LOCALE";
// PrettierJS =>
var LONGER_LONGER_LONGER_LONGER_LONGER_LOCALE_REQUEST_ATTRIBUTE_NAME =
  AngularCookieLocaleContextResolver.class.getName() + ".LOCALE";

private static final String LOCALE_REQUEST_ATTRIBUTE_NAME = AngularCookieLocaleContextResolver.class.getName()+ ".LOCALE";
// Prettier-Java =>
private static final String LOCALE_REQUEST_ATTRIBUTE_NAME = AngularCookieLocaleContextResolver
  .class
    .getName()
    + ".LOCALE";

// It seems prettier tries to put the second variable on a second line and then only try to break the second variable if it still exceeds the 80 character line
if(aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName && anotherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName)
{ // do something
}
// PrettierJS =>
if (
  aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName &&
  anotherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName
) {
  // do something
}
// Prettier-Java =>
if (aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName
  && anotherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName) { // do something
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
jhabercommented, Sep 30, 2019

but we can move the && to the next line

Is it common to put && on the next line in Java?

Just wanted to chime in that putting the && on the next line is in fact common in Java. Many companies (including us) piggyback on the Google code style for Java which uses this pattern: https://google.github.io/styleguide/javaguide.html#s4.5.1-line-wrapping-where-to-break

When a line is broken at a non-assignment operator the break comes before the symbol. (Note that this is not the same practice used in Google style for other languages, such as C++ and JavaScript.)

Not a dealbreaker for us, but if there was an option to put these operators on the next line we would use that option

1reaction
bd82commented, Jun 19, 2019

but we can move the && to the next line

Is it common to put && on the next line in Java?

Probably a mix of both result like:

@DanielFran I think the example by @clement26695 is slightly clearer, but regardless of my own personal opinion on the topic, should not we closely match the style of prettier-js simplify because it is much more mature and thus we would likely avoid pitfalls and issues that they already resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prettier · Opinionated Code Formatter
What is Prettier? An opinionated code formatter; Supports many languages; Integrates with most editors; Has few options ...
Read more >
Effortless JavaScript formatting with Prettier JS | by Ben Johnson
Prettier reformats your JavaScript for consistency while ensuring that your code fits into a prescribed line length limit. In doing this, it ...
Read more >
Automated code formatting with Prettier
Run Prettier on a file​​ Now, if you open a JavaScript file and select "Format Document" in the Command Palette Prettier will tidy...
Read more >
Prettier.js Method Arguments on newline formatting
I'm running Prettier.js (VSCode plugin)/ prettier-eslint-cli . It formats method arguments that go over the 80 character limit as the ...
Read more >
Prettier + Format On Save = Never worry about ... - Scott Sauber
Prettier takes JavaScript code in, runs some of its formatting rules ... Note how VS Code gives autocompletion for the different settings ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found