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

AnnotationRule formatting uncertainties #556

Closed
romtsn opened this issue Aug 5, 2019 · 5 comments · Fixed by #642
Closed

AnnotationRule formatting uncertainties #556

romtsn opened this issue Aug 5, 2019 · 5 comments · Fixed by #642

Comments

@romtsn
Copy link
Collaborator

romtsn commented Aug 5, 2019

I have a following Retrofit interface:

interface UserService {

    fun updateMarketingConsent(
        @Path("userId") userId: String,
        @Path("context") context: String,
        @Body body: MarketingConsent
    ): Completable

    fun showUser(@Path("id") userId: String, @Query("include") include: String? = null, @QueryMap fields: Map<String, String> = emptyMap()): Single

    fun logout(@Path("userId") userId: String): Completable
}

Running ktlint in --format mode gives the following output:

interface UserService {

    fun updateMarketingConsent(
        @Path("userId")
        userId: String,
        @Path("context")
        context: String,
        @Body body: MarketingConsentStructure
    ): Completable

    fun showUser(
        @Path("id")
        userId: String,
        @Query("include") include: String? = null, @QueryMap fields: Map<String, String> = emptyMap()
    ): Single

    fun logout(
        @Path("userId")
        userId: String
    ): Completable
}

Imo, the latter is way less readable. I went through the official styleguide, but I think an annotation with arguments should be allowed for method params (even though not sure that it's applicable for all possible cases).

Also in the showUser function, the last two parameters should be placed on different lines (so the with-argument annotation followed by no-argument annotation). Cause otherwise the parameter-list-wrapping rules kicks in. This is most likely a bug in formatter, right?

@shashachu
Copy link
Contributor

Ah, yeah. I don't think the rule was intended for parameter annotations. We can put up a diff to have it ignore those annotations completely.

@francescocervone
Copy link
Contributor

Is there a way to disable the annotation rule?

@romtsn
Copy link
Collaborator Author

romtsn commented Aug 6, 2019

@francescocervone disabled_rules=experimental:annotation in your .editorconfig

@arturbosch
Copy link
Contributor

+1 for this change

@yukukotani
Copy link
Contributor

I think readability and following official style are both important. I suggest to create two codestyle (#548), official one and strong one.

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

Successfully merging a pull request may close this issue.

5 participants