Bot releases are visible (Hide)
Support of Java 15 ! 🚀
Support of Text blocks
Support of new switch rules and yield statements
Improve throws rendering (From @jhaber: #384)
// Input
void throwException7(String string1, String string2, String string3, String string4) throws RuntimeException {
throw new RuntimeException();
}
// Prettier 0.8.3
void throwException7(
String string1,
String string2,
String string3,
String string4
)
throws RuntimeException {
throw new RuntimeException();
}
// Prettier 1.0.0
void throwException7(
String string1,
String string2,
String string3,
String string4
) throws RuntimeException {
throw new RuntimeException();
}
Published by pascalgrimaud about 4 years ago
Published by pascalgrimaud about 4 years ago
Published by clementdessoude about 4 years ago
// Input
class Indent {
void indetMethod() {
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo()
.anotherInvocation(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
myInstanceObject
.assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
}
}
// Output
class Indent {
void indetMethod() {
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo()
.anotherInvocation(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa,
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
);
myInstanceObject
.assertThat(
useraaaaaaaaaaojzapjzpozjapjzpoajzpozaaaaaaaaaaaMapperlaaaaaaaaaaaaaaaaaaaaaaaa
)
.isEqualTo();
}
}
// Throws in Prettier 0.8.0
double[][]::new
// Prettier 0.9.0
double[][]::new
Published by clementdessoude over 4 years ago
[
"variableInitializerList",
"block",
"blockStatements",
"blockStatement",
"localVariableDeclarationStatement",
"localVariableDeclaration",
"localVariableType",
"statement",
"statementWithoutTrailingSubstatement",
"emptyStatement",
"labeledStatement",
"expressionStatement",
"statementExpression",
"ifStatement",
"assertStatement",
"switchStatement",
"switchBlock",
"switchCase",
"switchLabel",
"enumConstantName",
"whileStatement",
"doStatement",
"forStatement",
"basicForStatement",
"forInit",
"forUpdate",
"statementExpressionList",
"enhancedForStatement",
"breakStatement",
"continueStatement",
"returnStatement",
"throwStatement",
"synchronizedStatement",
"tryStatement",
"catches",
"catchClause",
"catchFormalParameter",
"catchType",
"finally",
"tryWithResourcesStatement",
"resourceSpecification",
"resourceList",
"resource",
"resourceInit",
"variableAccess",
"isBasicForStatement",
"isLocalVariableDeclaration",
"classDeclaration",
"normalClassDeclaration",
"classModifier",
"typeParameters",
"typeParameterList",
"superclass",
"superinterfaces",
"interfaceTypeList",
"classBody",
"classBodyDeclaration",
"classMemberDeclaration",
"fieldDeclaration",
"fieldModifier",
"variableDeclaratorList",
"variableDeclarator",
"variableDeclaratorId",
"variableInitializer",
"unannType",
"unannPrimitiveType",
"unannReferenceType",
"unannClassOrInterfaceType",
"unannClassType",
"unannInterfaceType",
"unannTypeVariable",
"methodDeclaration",
"methodModifier",
"methodHeader",
"result",
"methodDeclarator",
"receiverParameter",
"formalParameterList",
"formalParameter",
"variableParaRegularParameter",
"variableArityParameter",
"variableModifier",
"throws",
"exceptionTypeList",
"exceptionType",
"methodBody",
"instanceInitializer",
"staticInitializer",
"constructorDeclaration",
"constructorModifier",
"constructorDeclarator",
"simpleTypeName",
"constructorBody",
"explicitConstructorInvocation",
"unqualifiedExplicitConstructorInvocation",
"qualifiedExplicitConstructorInvocation",
"enumDeclaration",
"enumBody",
"enumConstantList",
"enumConstant",
"enumConstantModifier",
"enumBodyDeclarations",
"isClassDeclaration",
"identifyClassBodyDeclarationType",
"isDims",
"constantExpression",
"expression",
"lambdaExpression",
"lambdaParameters",
"lambdaParametersWithBraces",
"lambdaParameterList",
"inferredLambdaParameterList",
"explicitLambdaParameterList",
"lambdaParameter",
"regularLambdaParameter",
"lambdaParameterType",
"lambdaBody",
"ternaryExpression",
"binaryExpression",
"unaryExpression",
"unaryExpressionNotPlusMinus",
"primary",
"primaryPrefix",
"primarySuffix",
"fqnOrRefType",
"fqnOrRefTypePartRest",
"fqnOrRefTypePartCommon",
"fqnOrRefTypePartFirst",
"parenthesisExpression",
"castExpression",
"primitiveCastExpression",
"referenceTypeCastExpression",
"newExpression",
"unqualifiedClassInstanceCreationExpression",
"classOrInterfaceTypeToInstantiate",
"typeArgumentsOrDiamond",
"diamond",
"methodInvocationSuffix",
"argumentList",
"arrayCreationExpression",
"arrayCreationDefaultInitSuffix",
"arrayCreationExplicitInitSuffix",
"dimExprs",
"dimExpr",
"classLiteralSuffix",
"arrayAccessSuffix",
"methodReferenceSuffix",
"identifyNewExpressionType",
"isLambdaExpression",
"isCastExpression",
"isPrimitiveCastExpression",
"isReferenceTypeCastExpression",
"isRefTypeInMethodRef",
"interfaceDeclaration",
"normalInterfaceDeclaration",
"interfaceModifier",
"extendsInterfaces",
"interfaceBody",
"interfaceMemberDeclaration",
"constantDeclaration",
"constantModifier",
"interfaceMethodDeclaration",
"interfaceMethodModifier",
"annotationTypeDeclaration",
"annotationTypeBody",
"annotationTypeMemberDeclaration",
"annotationTypeElementDeclaration",
"annotationTypeElementModifier",
"defaultValue",
"annotation",
"elementValuePairList",
"elementValuePair",
"elementValue",
"elementValueArrayInitializer",
"elementValueList",
"identifyInterfaceBodyDeclarationType",
"identifyAnnotationBodyDeclarationType",
"isSimpleElementValueAnnotation",
"literal",
"integerLiteral",
"floatingPointLiteral",
"booleanLiteral",
"moduleName",
"packageName",
"typeName",
"expressionName",
"methodName",
"packageOrTypeName",
"ambiguousName",
"compilationUnit",
"ordinaryCompilationUnit",
"modularCompilationUnit",
"packageDeclaration",
"packageModifier",
"importDeclaration",
"typeDeclaration",
"moduleDeclaration",
"moduleDirective",
"requiresModuleDirective",
"exportsModuleDirective",
"opensModuleDirective",
"usesModuleDirective",
"providesModuleDirective",
"requiresModifier",
"isModuleCompilationUnit",
"primitiveType",
"numericType",
"integralType",
"floatingPointType",
"referenceType",
"classOrInterfaceType",
"classType",
"interfaceType",
"typeVariable",
"dims",
"typeParameter",
"typeParameterModifier",
"typeBound",
"additionalBound",
"typeArguments",
"typeArgumentList",
"typeArgument",
"wildcard",
"wildcardBounds"
]
// Input
public enum Enum {
}
// Prettier v0.7.1
public enum Enum {
,
}
// Prettier v0.8.0
public enum Enum {}
Add support for trailing commas option (#354)
For enumerations:
// Input
public enum Enum {
ONE, TWO, THREE
}
// Output
public enum Enum {
ONE,
TWO,
THREE,
}
For arrays:
// Input
public class T {
void t() {
int[] ints = { 1, 2, 3, };
int[] ints = { aVeryLongArrayValue, anotherVeryLongArrayValue, andYetAnotherVeryLongArrayValue };
}
}
// Output
public class T {
void t() {
int[] ints = { 1, 2, 3 };
int[] ints = {
aVeryLongArrayValue,
anotherVeryLongArrayValue,
andYetAnotherVeryLongArrayValue,
};
}
}
By default, remove trailing comma in arrays (#354)
// Input
public class T {
void t() {
int[] ints = { 1, 2, 3, };
}
}
// Output
public class T {
void t() {
int[] ints = { 1, 2, 3 };
}
}
Allow blank lines in enumerations' constant list (#350)
// Input
public enum OtherEnum {
ONE, TWO,
THREE,
FOUR,
/* Five */
FIVE,
/* Six */
SIX
}
// Output
public enum OtherEnum {
ONE,
TWO,
THREE,
FOUR,
/* Five */
FIVE,
/* Six */
SIX
}
Always add a blank line between an enumeration's constants and declarations (#351)
// This input
public enum EnumWithExtraCommaAndEnumBodyDeclarations {
THIS_IS_GOOD("abc"),
THIS_IS_FINE("abc");
public static final String thisWillBeDeleted = "DELETED";
}
// will be formatted to this output
public enum EnumWithExtraCommaAndEnumBodyDeclarations {
THIS_IS_GOOD("abc"),
THIS_IS_FINE("abc");
public static final String thisWillBeDeleted = "DELETED";
}
Fix blank lines with empty statements (#360)
// Input
public class Test {
public TestField testField;;
@Override
public void someMethod() {}
}
// Output (v0.6.0)
public class Test {
public TestField testField;
@Override
public void someMethod() {}
}
// Output (v0.7.0)
public class Test {
public TestField testField;
@Override
public void someMethod() {}
}
Fix line wrapping in switch statements (#359)
// Input
public String shouldWrapEvenForSmallSwitchCases() {
switch (answer) { case "YES": return "YES"; default: return "NO"; }
}
// Output (v0.6.0)
public String shouldWrapEvenForSmallSwitchCases() {
switch (answer) { case "YES": return "YES"; default: return "NO"; }
}
// Output (v0.7.0)
public String shouldWrapEvenForSmallSwitchCases() {
switch (answer) {
case "YES":
return "YES";
default:
return "NO";
}
}
Fix stable reformating of comments in binary expression (#353)
// Input
public boolean binaryOperationWithComments() {
boolean a = one || two >> 1 // one
// two
// three
|| // five
// four
three;
boolean b = one || two >> 1 // one
// two
// three
||
three;
boolean c = one || two >> 1 // one
// two
// three
|| three;
return a || b || c;
}
// Output (v0.6.0)
public boolean binaryOperationWithComments() {
boolean a =
one ||
two >> 1 // two // one
// three
|| // five
// four
three;
boolean b =
one ||
two >> 1 // two // one
// three
||
three;
boolean c =
one ||
two >> 1 // two // one
// three
||
three;
return a || b || c;
}
// Output (v0.7.0)
public boolean binaryOperationWithComments() {
boolean a =
one ||
two >> 1 || // one
// five
// two
// three
// four
three;
boolean b =
one ||
two >> 1 || // one
// two
// three
three;
boolean c =
one ||
two >> 1 || // one
// two
// three
three;
return a || b || c;
}
Fix comments indentation when they are at the end of a block: indent the comments based on the block they are in (#345)
// Input
public class T {
int i;
// comment
}
// Output (v0.6.0)
public class T {
int i;
// comment
}
// Output (v0.7.0)
public class T {
int i;
// comment
}
Fix respect of blank lines with comments (#348)
// Input
void t() {
int i;
// comment
int j;
}
// Output (v0.6.0)
void t() {
int i;
// comment
int j;
}
// Output (v0.7.0)
void t() {
int i;
// comment
int j;
}