Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting not stable #443

Closed
martijndwars opened this issue Dec 5, 2020 · 2 comments · Fixed by #457
Closed

Formatting not stable #443

martijndwars opened this issue Dec 5, 2020 · 2 comments · Fixed by #457

Comments

@martijndwars
Copy link

martijndwars commented Dec 5, 2020

Prettier-Java 1.0.1 (through Prettier Maven Plugin 0.12)

Similar to #368, code needs to be formatted multiple times before it stabilizes.

# .prettierrc
{
  "overrides": [
    {
      "files": "*.md",
      "options": {
        "proseWrap": "always"
      }
    }
  ],
  "printWidth": 120,
  "semi": true,
  "singleQuote": true,
  "bracketSpacing": true,
  "arrowParens": "always",
  "trailingComma": "none"
}

Input:

package abc;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Foo {

  public static final List<Object> XXXXXXXXXXXXXXXXXX = Collections.unmodifiableList(
    Arrays.asList(// a
    // b
    // c
    // d
    )
  );
}

Output after first run:

package abc;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Foo {

  public static final List<Object> XXXXXXXXXXXXXXXXXX = Collections.unmodifiableList(
    Arrays.asList(// b // a
    // c
    // d
    )
  );
}

Output after second run:

package abc;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Foo {

  public static final List<Object> XXXXXXXXXXXXXXXXXX = Collections.unmodifiableList(
    Arrays.asList(// c // b // a
    // d
    )
  );
}

I won't go for the third run; I guess the pattern is clear.

Expected behavior:
It is probably not very common to put single-line comments inside a parameter list. Nevertheless, it is valid Java code, so Prettier should be able to format it. Multiple runs of Prettier should not produce different outputs, but Prettier should immediately produce a stable output.

@martijndwars martijndwars changed the title Formatting not deterministic/idempotent Formatting not stable Dec 5, 2020
@clementdessoude
Copy link
Contributor

Thank you for reporting this! I will try to have a look in the next few days

@clementdessoude
Copy link
Contributor

I finally took some time to dig in the issue ! Sorry for the delay @martijndwars !

I opened a PR that should hopefully should fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants