Skip to content

Add braceStyle option with same-line (default) and next-line choices.#840

Closed
motlin wants to merge 1 commit intojhipster:mainfrom
motlin:allman-style-braces
Closed

Add braceStyle option with same-line (default) and next-line choices.#840
motlin wants to merge 1 commit intojhipster:mainfrom
motlin:allman-style-braces

Conversation

@motlin
Copy link
Copy Markdown
Contributor

@motlin motlin commented Apr 5, 2026

What changed with this PR:

Added a braceStyle option with two choices:

  • same-line (default) — opening braces on the same line (K&R style, existing behavior)
  • next-line — opening braces on the next line (Allman style)

This applies to all block constructs: class/interface/enum bodies, method bodies, control flow statements (if/else, for, while, do-while, try/catch/finally, switch, synchronized), static and instance initializers, anonymous classes, lambda blocks, and array initializers.

Example

Input

public class HelloWorld {
    public void greet(String name) {
        if (name != null) {
            System.out.println("Hello, " + name);
        } else {
            System.out.println("Hello, World");
        }
    }
}

Output

With { "braceStyle": "next-line" }:

public class HelloWorld
{
  public void greet(String name)
  {
    if (name != null)
    {
      System.out.println("Hello, " + name);
    }
    else
    {
      System.out.println("Hello, World");
    }
  }
}

Relative issues or prs:

@motlin motlin force-pushed the allman-style-braces branch from 6c4fd06 to 621f173 Compare April 5, 2026 19:56
@DanielFran DanielFran requested a review from jtkiesel April 10, 2026 10:12
@jtkiesel
Copy link
Copy Markdown
Contributor

@motlin Thank you for your interest in contributing to Prettier Java!

Prettier is an opinionated formatter, and this Java plugin is as well. Prettier themselves have decided against supporting other brace styles (as is evidenced by every issue you linked being closed), and the K&R style is the standard and dominant style for braces in Java. Prettier offers very few options on purpose, and almost never add new options as it goes directly against the primary goal of Prettier (to avoid debates over different styles). As such, we will not integrate this option.

That being said, if you have other ideas for improvements to Prettier Java, please do create an issue as I am more than happy to discuss their viability and whether we would accept such a contribution!

@jtkiesel jtkiesel closed this Apr 26, 2026
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 this pull request may close these issues.

2 participants