Skip to content
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

Print width not obeyed on assignments #527

Closed
jtkiesel opened this issue Feb 8, 2022 · 6 comments · Fixed by #564
Closed

Print width not obeyed on assignments #527

jtkiesel opened this issue Feb 8, 2022 · 6 comments · Fixed by #564
Labels
area: bug 🐛 Something isn't working $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $200

Comments

@jtkiesel
Copy link
Contributor

jtkiesel commented Feb 8, 2022

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 prettier/prettier#2482. However, prettier/prettier#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).

@clementdessoude
Copy link
Contributor

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

@clementdessoude clementdessoude added the area: bug 🐛 Something isn't working label Mar 21, 2022
@pascalgrimaud pascalgrimaud added $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $200 labels Mar 21, 2022
@pascalgrimaud
Copy link
Member

as it's a bug, let's start with this bounty. If it's more work than expected, I'll increase it

@jtkiesel
Copy link
Contributor Author

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?

@pascalgrimaud
Copy link
Member

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 :)

@clementdessoude
Copy link
Contributor

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 !

@jtkiesel
Copy link
Contributor Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: bug 🐛 Something isn't working $$ bug-bounty $$ https://www.jhipster.tech/bug-bounties/ $200
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants