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

Unexpected new line when assigning to a class member #638

Closed
mgansler opened this issue Jan 19, 2024 · 0 comments · Fixed by #641
Closed

Unexpected new line when assigning to a class member #638

mgansler opened this issue Jan 19, 2024 · 0 comments · Fixed by #641

Comments

@mgansler
Copy link

Prettier-Java 2.5.0

# Options (if any):
--print-width 140

Input:

class Foo {

    public Foo(String a, String b, String c, String d, String e, String f) {}
}

public class MyPrettierTest {

    private Foo foo;

    @BeforeEach
    void beforeEach() {
        foo = new Foo("aaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccc", "dddddddddddddddddddd", "eeeeeeeeeeeeeeeeeeee", "ffffffffffffffffffff");
        final Foo bar = new Foo("aaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccc", "dddddddddddddddddddd", "eeeeeeeeeeeeeeeeeeee", "ffffffffffffffffffff");
    }
}

Output:

    void beforeEach() {
        foo =
            new Foo(
                "aaaaaaaaaaaaaaaaaaaa",
                "bbbbbbbbbbbbbbbbbbbb",
                "cccccccccccccccccccc",
                "dddddddddddddddddddd",
                "eeeeeeeeeeeeeeeeeeee",
                "ffffffffffffffffffff"
            );
        final Foo bar = new Foo(
            "aaaaaaaaaaaaaaaaaaaa",
            "bbbbbbbbbbbbbbbbbbbb",
            "cccccccccccccccccccc",
            "dddddddddddddddddddd",
            "eeeeeeeeeeeeeeeeeeee",
            "ffffffffffffffffffff"
        );
    }

Expected behavior:

    void beforeEach() {
        foo = new Foo(
            "aaaaaaaaaaaaaaaaaaaa",
            "bbbbbbbbbbbbbbbbbbbb",
            "cccccccccccccccccccc",
            "dddddddddddddddddddd",
            "eeeeeeeeeeeeeeeeeeee",
            "ffffffffffffffffffff"
        );
        final Foo bar = new Foo(
            "aaaaaaaaaaaaaaaaaaaa",
            "bbbbbbbbbbbbbbbbbbbb",
            "cccccccccccccccccccc",
            "dddddddddddddddddddd",
            "eeeeeeeeeeeeeeeeeeee",
            "ffffffffffffffffffff"
        );
    }

I would expect no new line in both cases, weather I assign to a class member or local variable. Personally, I wouldn't mind too much but we are also using SonarLint which reports a false positive (Unwritten field) for

foo =
    new Foo(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant