Skip to content

Comment before // prettier-ignore on an expression fails with "Comment was not printed" #1115

Closed

Description

@2is10

Prettier-Java 2.11.0

Input:

class A {
  Object[] a = {
    // explain
    // prettier-ignore
    foo(1,
        2),
  };
}
class A {
  Object f(boolean c) {
    return c
      ? a()
      : // prettier-ignore
        // explain
        b(1,   2);
  }
}

Output:

[error] A.java: Error: Comment "// explain" was not printed. Please report this error!

(Same error for both inputs.)

Expected behavior: Both comments are kept, and the ignored expression is printed as-is. For the first input:

class A {

  Object[] a = {
    // explain
    // prettier-ignore
    foo(1,
        2),
  };
}

Note: This issue is similar to #1098, but that one is about @formatter:on and @formatter:off comments.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions