prettier-java
prettier-java copied to clipboard
fix: improve throws formatting
What changed with this PR:
Constructors/methods with throws
clauses now break on their comma-separated list of exception classes rather than violating printWidth, and the left curly brace of the body is broken when this happens in order to separate the exception classes from the body (since they will be at the same indentation).
Example
Input
class Example {
Example(String arg1, String arg2)
throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
Example(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
) throws RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
Example(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
)
throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
void example1(String arg1, String arg2)
throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
void example2(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
) throws RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
void example3(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
)
throws RuntimeException, RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
}
Output
class Example {
Example(String arg1, String arg2) throws
RuntimeException,
RuntimeException,
RuntimeException,
RuntimeException
{
throw new RuntimeException();
}
Example(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
) throws RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
Example(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
) throws
RuntimeException,
RuntimeException,
RuntimeException,
RuntimeException
{
throw new RuntimeException();
}
void example1(String arg1, String arg2) throws
RuntimeException,
RuntimeException,
RuntimeException,
RuntimeException
{
throw new RuntimeException();
}
void example2(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
) throws RuntimeException, RuntimeException, RuntimeException {
throw new RuntimeException();
}
void example3(
String arg1,
String arg2,
String arg3,
String arg4,
String arg5,
String arg6
) throws
RuntimeException,
RuntimeException,
RuntimeException,
RuntimeException
{
throw new RuntimeException();
}
}
Relative issues or prs:
Closes #286 Closes #429
@clementdessoude I'm curious what your thoughts are on the formatting decisions I made here. Could you take a look, whenever you have the time?