jhipster / jhipster/prettier-java

Enforce braces around conditionals

Offen
#459 0 Kommentare 25 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: enhancement :wrench:
Vorherrschende Sprache
Java
Sterne
1.2k
Forks
120
Ø Merge
1 T. 14 Std.
Gemergte PRs (30 T.)
27

Beschreibung

Wanted to get thoughts on prettier enforcing braces around conditionals (example below). I believe prettier-js has shot down this request in the past on the grounds that they don't want to modify the AST, but I'm not sure if prettier-java has already crossed that bridge. It would probably be a controversial decision and is maybe a slippery slope, but I think it's pretty well-established at this point that using braces around conditionals is a best practice for correctness and maintainability, so I think it would be reasonable for prettier-java to enforce it.

**Prettier-Java 1.0.2*

```sh
# Options (if any):
--print-width 80
```

**Input:**

```java
public class Test {

public void method() {
if (true) System.out.println("hi");
}
}
```

**Output:**

```java
public class Test {

public void method() {
if (true) System.out.println("hi");
}
}
```

**Expected behavior:**

```java
public class Test {

public void method() {
if (true) {
System.out.println("hi");
}
}
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by reproducing the Java input with Prettier-Java 1.0.2 and compare the current output with the expected braced form in this issue. Investigate how conditional statements are represented and formatted, then determine the scope of enforcing braces consistently. Done means the example formats with braces and related conditional cases are covered by tests.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.