Skip to content
New issue

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

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

Already on GitHub? # to your account

Format can causes compile error if function has multi line comments #2355

Closed
RyosukeFukatani opened this issue Nov 15, 2023 · 2 comments · Fixed by #2375
Closed

Format can causes compile error if function has multi line comments #2355

RyosukeFukatani opened this issue Nov 15, 2023 · 2 comments · Fixed by #2375

Comments

@RyosukeFukatani
Copy link

Expected Behavior

Input

fun zero():
        Float
// comment1
// comment2
{
    return 0.0f
}

Expected result

fun zero(): Float {
// comment1
// comment2
    return 0.0f
}

or other compilable code.

Observed Behavior

Unfortunately we got non-compilable code.

fun zero(): Float
// comment1 { // comment2
        return 0.0f
    }

Your Environment

  • Version of ktlint used: 1.0.1
  • Relevant parts of the .editorconfig settings
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task):Gradle
  • Version of Gradle used (if applicable): 7.4.2
  • Operating System and version: mac OS 14.0
@RyosukeFukatani RyosukeFukatani changed the title format causes compile error if function Format can causes compile error if function has multi line comments Nov 15, 2023
@paul-dingemans
Copy link
Collaborator

Tnx fore the report. This is clearly a bug. I am not sure whether I can solve it within reasonable bounds. But least that I can do, is to disallow this particular location for a comment.

I don't know your usage of this way of commenting, but I would most likely have put the comment somewhere else.

@RyosukeFukatani
Copy link
Author

Thanks!
Actually, we consider this commenting style to be an unusual one and do not intend to continue using it.
In general, the following styles are considered preferable.

// comment1
// comment2
fun zero(): Float {
    return 0.0f
}

paul-dingemans added a commit that referenced this issue Nov 26, 2023
… brace (#2375)

* Move curly brace before all consecutive comments preceding that curly brace

Closes #2355
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants