Expected Rule behavior
Some libraries have a lot of annotations. This is more common in server-side libraries that use Spring, for instance. However, this can become quite cluttered when unformatted or unstructured.
Take a look at the following example from the wild:
@[Deprecated(DEPRECATED_ACCESS_API) AccessApiOverload]
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("frameColDataFrameKProperty")
public fun <C> AnyColumnGroupAccessor.frameCol(property: KProperty<DataFrame<C>>) = TODO()
I wonder, is KtLint familiar with the @[annotation1 annotation2] notation?
What I would recommend the rules to do:
- enforce lexicographical order of annotations, similar to imports, putting
@[] annotations at the bottom (as they're often the longest):
@JvmName("frameColDataFrameKProperty")
@Suppress("INAPPLICABLE_JVM_NAME")
@[AccessApiOverload Deprecated(DEPRECATED_ACCESS_API)]
public fun <C> AnyColumnGroupAccessor.frameCol(property: KProperty<DataFrame<C>>) = TODO()
- if a
@[] spans multiple lines, they should be indented together, with a single annotation per line (this is currently not recommended):
@[
JvmName("frameColDataFrameKProperty") Suppress("INAPPLICABLE_JVM_NAME")
AccessApiOverload
Deprecated(DEPRECATED_ACCESS_API)
]
public fun <C> AnyColumnGroupAccessor.frameCol(property: KProperty<DataFrame<C>>) = TODO()
should become something like this:
@[
AccessApiOverload
Deprecated(DEPRECATED_ACCESS_API)
JvmName("frameColDataFrameKProperty")
Suppress("INAPPLICABLE_JVM_NAME")
]
public fun <C> AnyColumnGroupAccessor.frameCol(property: KProperty<DataFrame<C>>) = TODO()
- Using
@[annotation] should be replaced by @annotation
- Using
@[annotation1 annotation2] on one line is fine if they fit. Else they should spread across multiple lines.
- Using 3+ annotations (or a customizable other number) without
@[] will be replaced with the @[annotation1 annotation2 annotation3] syntax
- Using multiple
@[] is allowed to group annotations together, but they should be ordered by width
@[AccessApiOverload Deprecated(DEPRECATED_ACCESS_API)]
@[JvmName("frameColDataFrameKProperty") Suppress("INAPPLICABLE_JVM_NAME")]
public fun <C> AnyColumnGroupAccessor.frameCol...
Some other ideas for improvements are welcome, of course :)
Unfortunately, there are not any guides regarding this Kotlin feature yet.
Expected Rule behavior
Some libraries have a lot of annotations. This is more common in server-side libraries that use Spring, for instance. However, this can become quite cluttered when unformatted or unstructured.
Take a look at the following example from the wild:
I wonder, is KtLint familiar with the
@[annotation1 annotation2]notation?What I would recommend the rules to do:
@[]annotations at the bottom (as they're often the longest):@[]spans multiple lines, they should be indented together, with a single annotation per line (this is currently not recommended):should become something like this:
@[ AccessApiOverload Deprecated(DEPRECATED_ACCESS_API) JvmName("frameColDataFrameKProperty") Suppress("INAPPLICABLE_JVM_NAME") ] public fun <C> AnyColumnGroupAccessor.frameCol(property: KProperty<DataFrame<C>>) = TODO()@[annotation]should be replaced by@annotation@[annotation1 annotation2]on one line is fine if they fit. Else they should spread across multiple lines.@[]will be replaced with the@[annotation1 annotation2 annotation3]syntax@[]is allowed to group annotations together, but they should be ordered by widthSome other ideas for improvements are welcome, of course :)
Unfortunately, there are not any guides regarding this Kotlin feature yet.