Add support to not add newlines in switch expressions
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Description
As a software engineer I would like to allow switch expressions to format the same as switch statements so that I can better align my code.
Currently if I were to try to format the following statement:
```java
return switch (av.type()) {
case B -> av.b().asByteArray();
case BOOL -> av.bool();
case BS -> av.bs().stream()
.map(SdkBytes::asByteArray)
.collect(toList());
default -> null;
}
```
It will be formatted as:
```java
return switch (av.type()) {
case B ->
av.b().asByteArray();
case BOOL ->
av.bool();
case BS ->
av.bs().stream()
.map(SdkBytes::asByteArray)
.collect(toList());
default -> null;
}
```
This makes the statement decidedly less readable and does not align with my switch statement settings.
### Use case/motivation
Allow for better readability and consistency with switch statements.
Willing to contribute with guidance.
### Related issues
_No response_
### Are you willing to submit a pull request?
Yes
### Code of Conduct
Yes
Contributor guide
Research direction
Start by locating the Java formatter entry point that handles switch expressions and compare it with switch statement formatting. Use the examples in the issue to verify that single-line arrow cases remain on one line, and add or update formatter coverage so the shown output is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100