prettier-java icon indicating copy to clipboard operation
prettier-java copied to clipboard

Needless parentheses around return

Open boris-petrov opened this issue 4 months ago • 1 comments

Prettier-Java 2.7.4

Playground link

--print-width 55

Input:

public abstract class Foo implements MyInterface {
  @Override public String foo() {
    return (
		true && false && true && false && true
	);
  }
}

Output:

public abstract class Foo implements MyInterface {

	@Override
	public String foo() {
		return (
			true && false && true && false && true
		);
	}
}

Expected behavior:

public abstract class Foo implements MyInterface {

	@Override
	public String foo() {
		return true && false && true && false && true;
	}
}

Note that making print-width 56 leads to a different (and still wrong result):

public abstract class Foo implements MyInterface {

	@Override
	public String foo() {
		return (true && false && true && false && true);
	}
}

In this case, it correctly puts the whole thing on a single line but it doesn't remove the parentheses.

boris-petrov avatar Aug 31 '25 11:08 boris-petrov

Hi, I’d like to work on this issue. Could you please assign it to me?

M-Vimal avatar Sep 21 '25 06:09 M-Vimal