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

String concatenation formatting #532

Open
JanecekPetr opened this issue Apr 5, 2022 · 2 comments
Open

String concatenation formatting #532

JanecekPetr opened this issue Apr 5, 2022 · 2 comments

Comments

@JanecekPetr
Copy link

Prettier-Java 1.6.1

Related to #77.
In this case we're getting compilable code, it's just sub-ideal.

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

Input:

PreparedStatement statement =
        connection.prepareStatement(
                "INSERT INTO noneofyourbusiness(" +
                        "field1," +
                        "field2," +
                        "field3," +
                        "field4) " +
                        "VALUES (?, ?, ?, ?)");

Output:

PreparedStatement statement = connection.prepareStatement(
    "INSERT INTO noneofyourbusiness(" + "field1," + "field2," + "field3," + "field4) " + "VALUES (?, ?, ?, ?)"
);

Expected behavior:
I see two options:

  • do not join the lines if they contain string concatenation like this
  • join, but make sure to get rid of all the concatenation
@clementdessoude
Copy link
Contributor

Hi @JanecekPetr,

I understand that this might be a little annoying.

However, I do not to get rid of the concatenation as it would change the AST, which we want to avoid.
And I don't think we want to introduce specificity for printing string concatenation either, as it would introduce some complexity for a limited (and maybe controversial) value.

@JanecekPetr
Copy link
Author

That's fair. So we do not want to make a single concatenated String, I'm fine with that.

Would it be better in those cases to not join the lines, but rather follow the human flow, and keep the strings on separate lines as a human put them there originally?

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

No branches or pull requests

2 participants