Skip to content

Wrong indentation for ternary in parentheses #786

@boris-petrov

Description

@boris-petrov

Prettier-Java 2.7.6

Playground link

--print-width 80

Input:

public abstract class Foo implements MyInterface {
	private Object foo() {
		return switch (value) {
			case Map<?, ?> map -> {
				yield x instanceof A a
					? true
					: (a != null
							? a
							: a
								.bbbbbbbbbbbbb()
								.ccccccccccccc()
								.ddddddddddddd());
			}
		};
	}
}

Output:

public abstract class Foo implements MyInterface {

	private Object foo() {
		return switch (value) {
			case Map<?, ?> map -> {
				yield x instanceof A a
					? true
					: (a != null
								? a
								: a
										.bbbbbbbbbbbbb()
										.ccccccccccccc()
										.ddddddddddddd());
			}
		};
	}
}

Expected behavior:

public abstract class Foo implements MyInterface {

	private Object foo() {
		return switch (value) {
			case Map<?, ?> map -> {
				yield x instanceof A a
					? true
					: (a != null
						? a
						: a
							.bbbbbbbbbbbbb()
							.ccccccccccccc()
							.ddddddddddddd());
			}
		};
	}
}

I'm not really certain how many tabs should be used for the indentation (due to the other issue I opened) but I don't think 3 is the right number.

In version 2.7.5 it was indented with 2 which again I think is wrong.

cc @jtkiesel

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions