-
Notifications
You must be signed in to change notification settings - Fork 111
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
Change "qualified Invocations" wrapping option to improve fluent API formatting #124
Comments
This is how Eclipse's formatter, upon which Java Format is based, works. If you want to keep the separate lines in certain cases you can disable the formatter. |
@wilkinsona with large adoption of builder, fluent apis, including reactor codebase, the proportion of affected code by this limitation increases, and this becomes impracticable to disable formatting for such large proportion of code. This prevents uses of the spring-javaformat in affected projects (e.g. spring-cloud/spring-cloud-app-broker#291 (comment)) Any chance to reopen this issue to discuss how to find solutions ? Googling "eclipse formatter for fluent apis" leads to the discussions/issues below, could they be applicable and useful to spring-javaformat ? https://bugs.eclipse.org/bugs/show_bug.cgi?id=547558 Formatter for lamda expression /CC @royclarkson |
Thanks for the references. I think they show that there's nothing that we can do here at the moment, particularly https://bugs.eclipse.org/bugs/show_bug.cgi?id=489444 which remains open. |
I wonder whether the existing flag |
In the end, we went the way that it's up to the programmer to decide the line breaks in every particular case. Thus, we don't restrict everything to one line nor splitting it per line every time (sometimes some short builder method chain or simple stream pipeline don't need to be wrapped). This, however, makes it relaxed enough to the point programmers are able to do line breaks anywhere they want, for example, in the middle of parameter list. It's not ideal, as we need to keep an eye out in the reviews, but still better than forcing everything on one line. |
Hello, I'm sorry to resurrect this, but I feel even though Mr. Wilkinson is probably aware of what we're talking about, he didn't actually address it explicitly. Eclipse already supports nice formatting of chained method calls, like the stream calls or any fluent calls, via the Qualified Invocations option. How does this not solve the problem? results in this code:
That's exactly what we want and should also be available programatically. If there's consensus on the change I'll gladly try and help with the code changes and the required communication to downstream projects (might require a major/minor version bump?). Let's please make the plugin actually useful by providing readable code :( |
I seem to remember the last time I looked at this I wasn't too happy with the results when we applied them to the Spring Boot codebase. I'll reopen the issue to check again, perhaps I was using a different setting. |
May I ask if there is a way to implement the line break of chained calls in the current version? except @Formatter:off |
@Hccake There's no way to do it with the current version. |
It's really sad 😢, when will this feature be implemented? |
@Hccake we don't have a target date, we're currently quite stacked up with other work. |
May I again, it's really sad 😢 |
@wilkinsona ask sincerely, when will implement this feature?
|
There's no target date at the moment. We have lots of other work on our plates at the moment that is higher priority. |
@philwebb since you've looked into this before and it didn't work out well for the Spring Boot project, would you consider allowing the qualified invocations setting to be configurable in the If so, I'd be willing to put in a PR based on your preferred approach. |
@andreasevers I just tried again using a branch with this change. The resulted in the following reformatting. I'd like to chat with the Boot team to see what we prefer. |
Here's some more tweaks and the result. |
Wow, this is exactly what we were looking for. As I understand the impact will be huge on the Spring Boot projects, and a release of this change is likely to take some consideration, I'll fork the repo and release my own version internally from your branch to unblock us. If there is anything I can do to help out anywhere let me know. |
I like the result of the further tweaks quite a lot. While it increases the line count, I think it makes the code easier to read. My preference is to go with philwebb/spring-javaformat@15397b3. |
I was really looking forward to such a change in the On a side note, applying this change to a code base can lead to a large modification, which can represent some noise in e.g. a |
So glad to see the result of @philwebb. Thank you! Is this likely to change in spring-javaformat and if so when? |
@lfvjimisola I'll merge this fix today but I want to try and iron out the IntelliJ plugin bugs before cutting a release. |
@philwebb When is it likely that 0.0.36 will be released? |
@lfvjimisola We don't have a scheduled date, but I suspect sometime next week. You can try the SNAPSHOTs today if you want to test things. |
I was surprised that custom wrapped code in a long method call chains is reformatted back to a single line. Affects stream() or any builder methods. For example:
Becomes:
This does not improve readability IMHO.
The text was updated successfully, but these errors were encountered: