redhat-developer / redhat-developer/vscode-java

Auto add brackets to if/else/while/do when format code

Open
#2,846 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code action enhancement formatter
Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

Is there a way to add brackets to the if/else/while/do statement when we use format code?

Environment
  • Operating System: Ubuntu 20.04
  • JDK version: 1.8.0, 17.05
  • Visual Studio Code version: 17.05
  • Java extension version:v1.13.0
Steps To Reproduce

Right-click -> Choose Format Doccment

Current Result
public int test(int x) {
    if (x == 1) return x + 1;
    return x * 10;
}
Expected Result
public int test(int x) {
    if (x == 1) {
        return x + 1;
    }
    return x * 10;
}
Additional Informations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example through VS Code's Format Document command with the Java extension, using the Ubuntu and JDK versions listed. Trace the formatting entry point and determine where conditional statements are formatted; done means if/else/while/do statements without brackets consistently receive brackets without changing other formatting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript, vscode
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.