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

Fix another issue with annotations incorrectly being forced to be multi-line #1762

Closed
wants to merge 1 commit into from

Conversation

shashachu
Copy link
Contributor

@shashachu shashachu commented Jan 4, 2023

Similar to #1688, an array of annotations would be forced to be multi-line if any of the entries had a parameter.

  • PR description added
  • tests are added
  • KtLint has been applied on source code itself and violations are fixed
  • documentation is updated
  • CHANGELOG.md is updated

…ti-line

Similar to pinterest#1688, an array of annotations would be forced to be multi-line if any of the entries had a parameter.
@paul-dingemans
Copy link
Collaborator

This PR seem to violate the Kotlin Coding Conventions regarding annotations:

The main rule is:

Place annotations on separate lines before the declaration to which they are attached, and with the same indentation:

@Target(AnnotationTarget.PROPERTY)
annotation class JsonExclude

An described exception is:

Annotations without arguments may be placed on the same line:

@JsonExclude @JvmField
var x: String

Although not mentioned explicitly, I read this as that by default all annotations go on a separate lines but it is allowed to put annotations without argument on the same line.

According to Androids Kotlin Style Guide it is not allowed to use annotations with parameters inside @[...]:

@[...] syntax may only be used with an explicit use-site target, and only for combining 2 or more annotations without arguments on a single line.

@field:[JvmStatic Volatile]
var disposable: Disposable? = null

Do you you have other references that would show that this should be allowed and is widely accepted in the community?

@shashachu
Copy link
Contributor Author

Ah, yes that seems to be what the docs imply. It's widely used in our own code but I don't have any idea whether it's industry standard. Let me do a bit of digging.

@shashachu
Copy link
Contributor Author

IntelliJ/Android Studio both allow the construct, but the docs do imply this is what you should do:

@[JvmStatic Provides]
@Foo("bar")
fun foo() = 42

Interestingly,

@[JvmStatic Provides] @Foo("bar")
fun foo() = 42

gets reformatted to the correct multi-line format in IJ, but not with ktlint. so I'll go ahead and file a separate issue.

@shashachu shashachu closed this Jan 4, 2023
@shashachu
Copy link
Contributor Author

#1765

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 this pull request may close these issues.

None yet

2 participants