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

Primary constructor formatting #37

Closed
hick209 opened this issue May 7, 2020 · 1 comment
Closed

Primary constructor formatting #37

hick209 opened this issue May 7, 2020 · 1 comment
Labels
formatting-discussions Discussions about how formatting should look like, when there's no clear consensus.

Comments

@hick209
Copy link
Contributor

hick209 commented May 7, 2020

For primary constructors ktfmt currently format this code

A

class MyView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    @AttrRes defaultAttr = ...,
    @StyleRes defaultStyle = ...,
) : View(context, attrs, defaultAttr, defaultStyle) {
  ...

into this

B

class MyView 
    @JvmOverloads
    constructor(
        context: Context,
        attrs: AttributeSet? = null,
        @AttrRes defaultAttr = ...,
        @StyleRes defaultStyle = ...,
    ) : View(context, attrs, defaultAttr, defaultStyle) {
  ...

It does not seem like A would violate the rectangle rule since, but in case it does, I believe I would prefer something more similar to this

C

class MyView 
@JvmOverloads
constructor(
    context: Context,
    attrs: AttributeSet? = null,
    @AttrRes defaultAttr = ...,
    @StyleRes defaultStyle = ...,
) : View(context, attrs, defaultAttr, defaultStyle) {
  ...

since it gets closer to what we have defined in the guidelines.

This is something that seems like it's still being debated (Kotlin/kotlin-style-guide#2) so there are no clear guidelines on what we should do here, still I say my personal preference is A > C >> B.

@hick209 hick209 added the formatting-discussions Discussions about how formatting should look like, when there's no clear consensus. label Jul 30, 2020
@hick209 hick209 closed this as completed Dec 9, 2020
@hick209
Copy link
Contributor Author

hick209 commented Dec 9, 2020

Closing as this was resolved in a96140e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting-discussions Discussions about how formatting should look like, when there's no clear consensus.
Projects
None yet
Development

No branches or pull requests

1 participant