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

Comment Formatting #679

Open
d-pizhuk opened this issue Aug 21, 2024 · 2 comments
Open

Comment Formatting #679

d-pizhuk opened this issue Aug 21, 2024 · 2 comments

Comments

@d-pizhuk
Copy link

prettier-plugin-java
version: 2.6.4

# Options (if any):
--print-width 120

Input:

// some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment
public SomeClass() {}

Output:

// some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment some comment
public SomeClass() {}

Expected behavior:
Does Prettier not format comment sections? As I see, it has even issues with formatting the code which is in one line with a comment. Is it right? Or there is some new version with fixed comment formatting?

@storylord85
Copy link

storylord85 commented Aug 29, 2024

found the same behavior

prettier-plugin-java
version: 2.6.4
prettier
version:3.3.3

additionally found out that prettier will do the formating twice of the same file as it will format the comment section wrong.

example

Input:

private boolean isClassList(Class<?> clazz) {
        if (clazz.isArray()) { //test
            return true;
        } else {
            return false;
        }
}

Output after first format call to prettier

private boolean isClassList(Class<?> clazz) {
        if (
            clazz.isArray()
        ) { //test
            return true;
        } else {
            return false;
        }
}

Output after second call to same file with no additional editing:

private boolean isClassList(Class<?> clazz) {
        if (clazz.isArray()) { //test
            return true;
        } else {
            return false;
        }
}

@jtkiesel
Copy link
Contributor

jtkiesel commented Sep 2, 2024

This is similar to #651, which asked for the same, though specifically mentioned Javadocs. At the moment, this plugin does not modify the contents of comments in any way, it merely moves them as necessary. Prettier itself has not yet implemented this either (see prettier/prettier#265), which I think is the primary reason we haven't done so in this plugin. The Prettier team seemed receptive to the idea of formatting comments when that issue was opened in 2017, but it's had very little activity since then. None of that is to say that we couldn't implement this ourselves, we just wouldn't be able to lean on the Prettier team's decisions made surrounding it.

The issue mentioned by @storylord85 is unrelated to wrapping comment contents, but instead seems to be related to #592.

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

No branches or pull requests

3 participants