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

Consecutive spaces and line break algorithm can cause trailing whitespace #1921

Open
dalewking opened this issue Jun 4, 2024 · 3 comments
Open
Labels

Comments

@dalewking
Copy link

dalewking commented Jun 4, 2024

Describe the bug
Stumbled upon this. Was adding some KDoc comments based on some text from elsewhere. That text had 2 spaces after a period and that happened to be where the line breaking algorithm broke the text but it resulted in a trailing whitespace on the line. This can be annoying because the IDE likes to remove them and in our case the generated code will be checked into git causing diffs

To Reproduce
Adding this line to a top level function spec will show it:

       addKdoc("@param xxxxxxxxxXXXXXXX Blah blah blah blah blah blah blah blah blah blah blah blah blah blah.  Blah\n")

Note that there are 2 spaces after the period.

The output will be:

/**
 * @param xxxxxxxxxXXXXXXX Blah blah blah blah blah blah blah blah blah blah blah blah blah blah. 
 * Blah
 */

which has a space at the end of the first line

Expected behavior
I expect the generated code to have no trailing whitespace

Additional context
My workaround is to collapse multiple spaces to 1

@dalewking dalewking added the bug label Jun 4, 2024
@Egorand
Copy link
Collaborator

Egorand commented Jun 5, 2024

I wonder if there are use cases where trailing whitespaces can be meaningful, and whether we'd be breaking those use cases by deleting whitespaces by default. I wouldn't want to us to introduce a parameter to control this behaviour either. Perhaps it's safer to leave this decision to library consumers?

@JakeWharton
Copy link
Collaborator

If you're inside a monospace span (single backtick delimited) you might want two spaces preserved.

@dalewking
Copy link
Author

In my case it is text coming from a swagger spec and whoever wrote it was following the old 2 spaces after a period convention.

Regarding the notion of preserving spaces in a monospace span the line wrapping itself would be a problem any way so whether you leave a trailing whitespace seems moot for that case.

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

No branches or pull requests

3 participants