-
Notifications
You must be signed in to change notification settings - Fork 506
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
Consider a rule to normalize annotation style #2172
Comments
This is an interesting proposal.
I would definetly favor to implement a global code style. Consistency in code style is a key factor in making code in a project easy to read. It might be best to create a separate rule for grouping annotation into arrays versus ungrouping annotations from arrays. This rule indeed would need a setting with the preferred style. The style could be one of following:
I wouldn't know what the best default would be. I have the feeling that the array annotations are more heavily used in Android development. The default can be set per coding style. |
I would favor to have each array of annotation to be on a separate line. So
Is it acceptable, or even favoured, to reorder annotations? Given original code:
When reordering is not allowed, this would become:
If reordering is allowed, it could be written as:
where ordering is:
|
If you want a single data point, I've never seen array annotations used, and I didn't even know it was a thing. I'm mostly work in Android, but do work on general JVM/KMP as well. |
We do use array notation for readability. Agree with Jake's original notation that we shouldn't mix the two on a single element, but imo both should be allowed. I would argue against any kind of reordering. |
This seems contractdictory to me. Given sample below:
A, B, E and G are all annotations without receivers. Jake's propopal is that those should be grouped into a single array. That would mean that the order of the annotations will change.
This would mean that whenever an element is annotation with an annotation containing parameters, that all other annotations on that element should be ungrouped as well. |
Parking the issue for now, due to lack of input / consensus. |
Expected Rule behavior
Enforce multiple annotations use array-form, individual-form, but not both at the same time in the same location.
I suspect people will also want to enforce one style over the other globally. That is to say, if there are multiple annotations at a site they must either use the
@[A B]
form or@A @B
form. I'm not sure enforcement of one style or the other by default makes sense, but that's a conversation we can have with the community.The Android style guide says that array-form can only be used with a declared annotation receiver and provided they do not have arguments (https://developer.android.com/kotlin/style-guide#annotations). I'm not sure this very specific restriction is worth fully honoring, but it's important to note since it's somewhat an argument against a global default style but not fully.
Some interesting cases to handle:
The text was updated successfully, but these errors were encountered: