-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Do not force a blank line above method #284
Comments
Since Also, the TS/JS parsers/builders never enforced this behavior. |
I'm not sure I agree with this. Here is an example where I think prettier-java should insert multiple newlines: package com.example;
import java.util.List;
public class ExampleClass {
private final int field = 1;
public void methodOne() {
// do nothing
}
public void methodTwo() {
// do nothing
}
} I think this should format as: package com.example;
import java.util.List;
public class ExampleClass {
private final int field = 1;
public void methodOne() {
// do nothing
}
public void methodTwo() {
// do nothing
}
} In particular I think it should enforce that there's exactly one newline between:
There are some more controversial questions like whether there should be a newline between class declaration and field declaration, or between static fields and non-static fields, but I'm hoping that the above list isn't particularly controversial |
@jhaber sure, every developer/team has its own habits.
I actually edited my fork to solve the issue, and I think this is easily doable. And remember
|
Yep, sorry if my wording wasn't clear. I was trying to express that there should be a newline between Forcing a newline between class declaration and the first method declaration happens to be my preference (especially if there is an annotation present on the method), but I understand this is probably going to be divisive |
Hi. I think the problem you're talking about is #271, isn't it? |
@murdos pretty much yes, but it's the opposite. Regarding the question
I'd vote for no, it's not needed always. In some cases it's reasonable for readability, in others not much. |
I left my thoughts on #271, maybe we should close this issue and consolidate discussion there? |
I feel like this could easily be added as a configuration option. |
It could be, but the goal of prettier is to (as much as possible) provide a single, opinionated style rather than supporting every possible formatting preference |
That's fair. Google's Java formatter has a similar philosophy, and my team at work switched away from it because Google's doesn't even allow customizing line lengths or tab widths. I only suggested a config because people in the two issues seem to disagree on a decision. |
Print width:
100
Input code:
Expected output:
Actual:
The text was updated successfully, but these errors were encountered: