format differences with PrettierJS
See original GitHub issueWe 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
- PR #223 (merged)
if(aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName && anotherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName)
{ // do something
}
// PrettierJS =>
if (
aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName &&
anotherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName
) {
// do something
}
// Prettier-Java =>
if (aVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName
&& anotherVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName) { // do something
}
- PR #222 :
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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-breakNot a dealbreaker for us, but if there was an option to put these operators on the next line we would use that option
Is it common to put && on the next line in Java?
@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?