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

Text block get formatted uggly #930

Open
scott-avery opened this issue Sep 18, 2023 · 8 comments
Open

Text block get formatted uggly #930

scott-avery opened this issue Sep 18, 2023 · 8 comments

Comments

@scott-avery
Copy link

What happened?

this tool formats text block in not ideal format.

see original verion.

    @Update("""
    update master_data_manager
    set version = version + 1, update_time = now(), update_by = #{userId}
    where site_id = #{siteId} and table_name = #{tableName}
    """)

output

    @Update(
            """
    update master_data_manager
    set version = version + 1, update_time = now(), update_by = #{userId}
    where site_id = #{siteId} and table_name = #{tableName}
    """)

What did you want to happen?

keep the same as original.

@talios
Copy link

talios commented Sep 22, 2023

+1000 on improving the formatting of text blocks, for me I find I use .formatted() at the end of them often and that also drops to the next line which looks ugly, kinda lie:

var text =
        """
    update master_data_manager
    set version = version + 1, update_time = now(), update_by = #{userId}
    where site_id = %s and table_name = #{tableName}
    """
         .formatted("site");

Ideally, the opening """ would also be hanging, and the code following on the same line, something like:

var text = """
    update master_data_manager
    set version = version + 1, update_time = now(), update_by = #{userId}
    where site_id = %s and table_name = #{tableName}
    """.formatted("site");

would be ideal.

@bmarwell
Copy link

bmarwell commented Oct 8, 2023

Example from a wiremock test case. A beauty in its own... don't you think? 😉

20231009_002339.jpg

@carterkozak
Copy link
Contributor

If memory serves, we don’t currently format text blocks, only the code around them. This is due to their structure being both a string a block which is indention-sensitive.
Definitely room for improvement on this :-)

@talios
Copy link

talios commented Oct 10, 2023

@carterkozak From memory, javac automatically strips away the incidental/grey white space (the initial indentation on the first line of the text block), so changing that initial base indentation shouldn't cause any issues - as long as any additional indentation is respected.

@rmannibucau
Copy link

+1 to get something more common/standard and less unlikely by default, formatting should stay well readable after all ;)

@cushon
Copy link
Contributor

cushon commented Mar 2, 2024

javac automatically strips away the incidental/grey white space (the initial indentation on the first line of the text block), so changing that initial base indentation shouldn't cause any issues - as long as any additional indentation is respected.

+1, there is a nice overview here: https://docs.oracle.com/en/java/javase/21/text-blocks/index.html#incidental-white-space

For what it's worth, the approach google-java-format is currently taking for text blocks is to re-indent them to the current continuation indent (see here).

@bmarwell
Copy link

bmarwell commented May 6, 2024

@CRogers any chance we can get an update here?

@mhagnumdw
Copy link

Another example case:

image

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

7 participants