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

Annotations get collapsed to the same line as code it affects #395

Closed
ukarlsson opened this issue Mar 27, 2023 · 6 comments
Closed

Annotations get collapsed to the same line as code it affects #395

ukarlsson opened this issue Mar 27, 2023 · 6 comments

Comments

@ukarlsson
Copy link

We are using ktfmt with the following gradle config

ktfmt {
    kotlinLangStyle()
}

The issue that annotations get formatted on the same line, e.g. we get lines like

        @Serializable @SerialName("native:live") object NativeLive : SpecificSettings()

        @Serializable @SerialName("native:self-paced") object NativeSelfPaced : SpecificSettings()

The Kotlinx documentation all have the annotations on different lines and I noticed that in ktfmt you also have annotations on different lines.

We would very much like ktfmt to format this like

        @Serializable
        @SerialName("native:live")
        object NativeLive : SpecificSettings()

        @Serializable
        @SerialName("native:self-paced")
        object NativeSelfPaced : SpecificSettings()

Using ktfmt version 0.43.0

Many thanks.

@ukarlsson ukarlsson changed the title Annotations are on same line Annotations get collapsed to the same line as code it affects Mar 27, 2023
@cgrushko
Copy link
Contributor

@strulovich , I remember you have thoughts on this?

@strulovich
Copy link
Contributor

If I recall correctly, the main reason we are at this state is since similar multiline formatting for annotated parameters look really bad.

  • We went back and forth whether to handle annotations with params differently (as the Kotlin guidelines suggests). In the end I think we do not, since it created many awkward instances.
  • Breaking annotations can make a list of annotated items look very awkward if the items are short. (It take a nicely formatted 5 lines turning them to 20 ones).
  • We can consider treating formatting differently according to the annotated target (i.e. treat properties differently than top level objects), but I think that will be a time sink with very little value.

Overall, this is basically working as intended right now. Without really strong support and argument to do it the opposite way I think we should keep it as is.

@ukarlsson
Copy link
Author

Ok thanks for your comments

@savl-2021
Copy link

Is there any progress?

@strulovich
Copy link
Contributor

There's no progress here. Also see #226

@hick209
Copy link
Contributor

hick209 commented Jun 5, 2024

See this comment here
#435 (comment)

Also this would violate this principle here that we try to follow for ktfmt

@hick209 hick209 closed this as completed Jun 5, 2024
@hick209 hick209 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2024
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

5 participants