Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettier-plugin-java

Package Overview
Dependencies
Maintainers
6
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-java - npm Package Versions

1245

1.2.0

Diff

Changelog

Source

v1.2.0

Enhancements

  • Supports of instance of pattern matching (#476)
// Input
if (o instanceof Integer i || p instanceof Point || q instanceof Circle c || r instanceof Square) {
  formatted = String.format("int %d", i);
} else if (o instanceof Long l) {
  formatted = String.format("long %d", l);
} else if (o instanceof Double d) {
  formatted = String.format("double %f", d);
} else if (o instanceof String s) {
  formatted = String.format("String %s", s);
}

// Output
if (
  o instanceof Integer i ||
  p instanceof Point ||
  q instanceof Circle c ||
  r instanceof Square
) {
  formatted = String.format("int %d", i);
} else if (o instanceof Long l) {
  formatted = String.format("long %d", l);
} else if (o instanceof Double d) {
  formatted = String.format("double %f", d);
} else if (o instanceof String s) {
  formatted = String.format("String %s", s);
}
  • Supports of sealed classes and interfaces (#478)
// Input
public sealed class Rectangle implements Shape permits Square {

  private final double length;
  private final double height;

  public Rectangle(double length, double height) {
    this.length = length;
    this.height = height;
  }

  @Override
  public double area() {
    return length * height;
  }
}

// Output
public sealed class Rectangle implements Shape permits Square {

  private final double length;
  private final double height;

  public Rectangle(double length, double height) {
    this.length = length;
    this.height = height;
  }

  @Override
  public double area() {
    return length * height;
  }
}

Miscellaneous

pascalgrimaud
published 1.1.1 •

Changelog

Source

v1.1.1

Fixes

  • Fix parsing records inside class declarations and records with simplified constructors (#470)

Miscellaneous

  • Update links to Chevrotain library (From @Austin-Scott: #472)
pascalgrimaud
published 1.1.0 •

Changelog

Source

v1.1.0

Enhancements

  • Supports of Records (#460)
// Input
public record Pet(
  @NotNull String name,
  int age,
  String... others,
  Object @Nullable... errorMessageArgs
) {
  public Pet {
    if (age < 0) {
      throw new IllegalArgumentException("Age cannot be negative");
    }

    if (name == null || name.isBlank()) {
      throw new IllegalArgumentException("Name cannot be blank");
    }
  }

  public void test() {}
}

// Output
public record Pet(
  @NotNull String name,
  int age,
  String... others,
  Object @Nullable... errorMessageArgs
) {
  public Pet {
    if (age < 0) {
      throw new IllegalArgumentException("Age cannot be negative");
    }

    if (name == null || name.isBlank()) {
      throw new IllegalArgumentException("Name cannot be blank");
    }
  }

  public void test() {}
}

cdessoude
published 1.0.2 •

Changelog

Source

v1.0.2

Fixes

  • Keep space between annotation and type identifiers in unannClassType expressions (#455)
// Input
class T {
  SomeClass.@Valid SomeInnerClass someInnerClass = someClass.getInteractions().get(0);

  void process(
    Map.@NonNull Entry<String, SkeletonConfiguration> entry,
    @NonNull Map<String, Object> context
  ) {}
}

// Prettier 1.0.1
class T {
  SomeClass.@ValidSomeInnerClass someInnerClass = someClass
    .getInteractions()
    .get(0);

  void process(
    Map.@NonNullEntry<String, SkeletonConfiguration> entry,
    @NonNull Map<String, Object> context
  ) {}
}

// Prettier 1.0.2
class T {

  SomeClass.@Valid SomeInnerClass someInnerClass = someClass
    .getInteractions()
    .get(0);

  void process(
    Map.@NonNull Entry<String, SkeletonConfiguration> entry,
    @NonNull Map<String, Object> context
  ) {}
}
  • Fix inconsistent indentation between chained method on method and new object (#456)
// Input
class T {

  public void method() {
    new Foo(stuff, thing, "auaaaaaaaaa some very long stuff", "some more")
      .bar(10);
    foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more")
      .bar(10);
  }
}

// Prettier 1.0.1
class T {

  public void method() {
    new Foo(stuff, thing, "auaaaaaaaaa some very long stuff", "some more")
      .bar(10);
    foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more")
      .bar(10);
  }
}

// Prettier 1.0.2
class T {

  public void method() {
    new Foo(stuff, thing, "auaaaaaaaaa some very long stuff", "some more")
      .bar(10);
    foo(stuff, thing, "some very longuuuuuuuuuuuuuu stuff", "some more")
      .bar(10);
  }
}

  • Fix unstable formatting for method invocations with only comments (#457)
// Input
class T {

  public void method() {
    Arrays.asList( // a
      // b
      // c
      // d
    );
  }
}

// Prettier 1.0.1
class T {

  public void method() {
    Arrays.asList( // b // a
      // c
      // d
    );
  }
}

// Prettier 1.0.2
class T {

  public void method() {
    Arrays.asList( // a
      // b
      // c
      // d
    );
  }
}

Miscellaneous

  • Update lodash dependency to 4.17.21 (#458)
cdessoude
published 1.0.1 •

Changelog

Source

v1.0.1

Fixes

  • Correct spaces emplacement in multi-value switch expression case label (#440)
// Input

public class Test {

  public void test(TestEnum testEnum) {
    switch (testEnum) {
      case FOO -> System.out.println("Foo!");
      case BAR, BAZ -> System.out.println("Not Foo!");
    }
  }
}

// Prettier 1.0.0

public class Test {

  public void test(TestEnum testEnum) {
    switch (testEnum) {
      case FOO -> System.out.println("Foo!");
      case BAR, BAZ -> System.out.println("Not Foo!");
    }
  }
}

// Prettier 1.0.1

public class Test {

  public void test(TestEnum testEnum) {
    switch (testEnum) {
      case FOO -> System.out.println("Foo!");
      case BAR, BAZ -> System.out.println("Not Foo!");
    }
  }
}

Miscellaneous

  • Update prettier dependency to 2.2.1
cdessoude
published 1.0.0 •

Changelog

Source

v1.0.0

Enhancements

  • 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();
}

Fixes

  • Parsing of unannPrimitiveType in primary (#421)

Miscellaneous

  • Update dependencies
pascalgrimaud
published 0.8.3 •

cdessoude
published 0.8.2 •

Changelog

Source

v0.8.2

Fixes

  • Revert: Parsing of unannPrimitiveType in primary (#421). It was causing a breaking change in the java-parser

  • uses exact dependencies when releasing a new version of java-parser and prettier-plugin-java

cdessoude
published 0.8.1 •

Changelog

Source

v0.8.1

Enhancements

  • Generated a type definition for the Java parser (#422)

Fixes

  • Wrong indent in some chained methods invocation (#404)
// 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();
  }
}

  • Parsing of unannPrimitiveType in primary (#421)
// Throws in Prettier 0.8.0
double[][]::new

// Prettier 0.9.0
double[][]::new
cdessoude
published 0.8.0 •

Changelog

Source

v0.8.0

Enhancements

  • Possibility to run the Prettier Java package on every entrypoint defined in the following list (#395):
    [
      "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"
    ];
    

Fixes

Re-Writer

  • Fix formatting of empty enums to not insert commas when trailing-comma is enabled #385)

    // Input
    public enum Enum {}
    
    // Prettier v0.7.1
    public enum Enum {
    
    }
    
    // Prettier v0.8.0
    public enum Enum {}
    
    
  • Fix formatting of enum with comments #385)

Miscellaneous

  • Update prettier dependency to 2.0.5 (#379) & (#400)
  • Binary artefacts creation for each release (#399)
  • Document Maven plugin (#394)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc