jhipster / jhipster/prettier-java

[2.10.0] Wrongly removes parentheses

Open
#948 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
120
Avg merge
1d 14h
Merged PRs (30d)
27

Description

**Prettier-Java 2.10.0**

```sh
--print-width 80
```

**Input:**

```java
return a != null && (b == c);
(minimumRelevanceScore * 2) - 1;
```

**Output:**

```java
return a != null && b == c;
minimumRelevanceScore * 2 - 1;
```

**Expected behavior:**
Unchanged.

The second line is not technically incorrect but I personally don't like parentheses removed in such expressions. There is a long-standing issue in Prettier for JS for the [same thing](https://github.com/prettier/prettier/issues/187). The first one is wrong because it changes the meaning of the program.

P.S. I now see that Prettier for JS does the same thing. Horrible. And maybe it's because of the same issue. I would like Prettier for Java to be better than that! 😄

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the Java snippets and --print-width 80, then trace the formatter logic responsible for removing parentheses. Done means the first expression retains parentheses so its meaning is unchanged, while the reported formatting behavior is covered by a regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.