Improve formatting of method will lot of parameters and with exception
See original GitHub issueSource:
public LoggingConfiguration(@Value("${spring.application.name}") String appName,
@Value("${server.port}") String serverPort,
JHipsterProperties jHipsterProperties,
ObjectMapper mapper)
throws JsonProcessingException {
// ...
}
Formatted with prettier 0.4.0:
public LoggingConfiguration(
@Value("${spring.application.name}") String appName,
@Value("${server.port}") String serverPort,
JHipsterProperties jHipsterProperties,
ObjectMapper mapper
)
throws JsonProcessingException {
// ...
}
I’m not really sure what the result should be, but the position of )
after the last parameter is a bit strange in regards to the exception.
Maybe:
public LoggingConfiguration(
@Value("${spring.application.name}") String appName,
@Value("${server.port}") String serverPort,
JHipsterProperties jHipsterProperties,
ObjectMapper mapper
) throws JsonProcessingException {
// ...
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:12 (5 by maintainers)
Top Results From Across the Web
java - How to format methods with large parameter lists
Personally, I prefer to break after each parameter if I have to break at all, i.e. public static Foo makeFoo( Foo foo, Bar...
Read more >CA2241: Provide correct arguments to formatting methods
Learn about code analysis rule CA2241: Provide correct arguments to formatting methods.
Read more >Are there guidelines on how many parameters a function ...
I've never seen a guideline, but in my experience a function that takes more than three or four parameters indicates one of two...
Read more >9 Best Practices to Handle Java Exceptions - Stackify
Handling Java exceptions isn't easy, especially for beginners. Read this post to understand exceptions and best practices for using them.
Read more >How To Use String Formatters in Python 3 - DigitalOcean
This tutorial will guide you through some of the common uses of string formatters in Python, which can help make your code and...
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
Prettier is an opinionated formatter, and it seems like one of those opinions is that either all elements in a group should line break, or none should (and prettier-java inherits this behavior from prettier since it’s a prettier plugin). The example above might look tidy because all of the arguments are the same type and happen to align nicely, but it quickly becomes text soup when that’s not the case, for example:
But like I said before, this style is just an opinion so there’s not much use in debating which way is objectively “right”. However, this opinion is pretty much at the core of prettier and unlikely to change. If you don’t like prettier’s opinions, google-java-format might be of interest, it’s another formatter that’s a bit less opinionated and also has IDE plugins available.
@MichielBugherJelli suggestion looks pretty good to me. Why keep every element to next line once reached print width. A smart wrap respecting print width value would be perfect.