Print width not obeyed on assignments
Prettier-Java 1.6.1
# Options:
--print-width 80
--tab-width 4
Input:
package org.prettier.java;
public class MyReallyLongClassName {
public void method() {
MyReallyLongClassName myReallyLongVariableName = new MyReallyLongClassName();
MyReallyLongClassName myReallyLongVariableName2 = myReallyLongMethodName();
}
public MyReallyLongClassName myReallyLongMethodName() {
return new MyReallyLongClassName();
}
}
Output:
package org.prettier.java;
public class MyReallyLongClassName {
public void method() {
MyReallyLongClassName myReallyLongVariableName = new MyReallyLongClassName();
MyReallyLongClassName myReallyLongVariableName2 = myReallyLongMethodName();
}
public MyReallyLongClassName myReallyLongMethodName() {
return new MyReallyLongClassName();
}
}
Expected behavior:
package org.prettier.java;
public class MyReallyLongClassName {
public void method() {
MyReallyLongClassName myReallyLongVariableName =
new MyReallyLongClassName();
MyReallyLongClassName myReallyLongVariableName2 =
myReallyLongMethodName();
}
public MyReallyLongClassName myReallyLongMethodName() {
return new MyReallyLongClassName();
}
}
I expect lines that exceed the configured print width to be broken after =.
This used to be an issue for Prettier with JavaScript as well, see https://github.com/prettier/prettier/issues/2482. However, https://github.com/prettier/prettier/pull/10222 seems to have fixed most of the issues (at least for the two examples I have given, of instantiation and method return value assignment).
Thanks for reporting this ! It is an issue only when the first element of the assignment is a new expression. Unfortunately, this part of the code is particularly complex due to the way the Java syntax is build around expressions. It should be possible to handle this use case, but I may need some time to investigate
as it's a bug, let's start with this bounty. If it's more work than expected, I'll increase it
In November I created a PR (#564) that fixes this, but the primary maintainer (@clementdessoude) seems to have been inactive on GitHub since then. I'm not sure who all of the maintainers of this project are, or who else may be able to review the PR (and hopefully merge it and create a new release). @pascalgrimaud Any advice?
I'll try to contact personaly @clementdessoude and let you know if no answer, I'll have a look to your PR, but I never work on this project :)
Hi @jtkiesel ! I'm so sorry, I had a few roughs months, I put this project aside for a moment... I will have a look right now ! Thanks for notifying @pascalgrimaud !
@clementdessoude No worries at all! I am sorry if I came off as impatient or rude. To be honest, this is my first contribution to OSS, so I wasn't sure of the etiquette. I hope that life is treating you better! Thank you and @pascalgrimaud both!