I cannot figure out a way to format `private val s...
# ktlint
m
I cannot figure out a way to format
private val styleSource: NullForUndefined<@Serializable(with = LayerSourceSerializer::class) SourceDto> = NullForUndefined(null)
to make the
AnnotationOnSeparateLine
rule happy. I'm using ktlint from detekt.
v
Just let ktlint fix and not complain and you see it. But as the rule says, it must be on a separate line:
Copy code
private val styleSource: NullForUndefined<
    @Serializable(with = LayerSourceSerializer::class)
    SourceDto
    > = NullForUndefined(null) to make the AnnotationOnSeparateLine
m
I still get a two warnings about AnnotationOnSeparateLine with that format. One after the
<
and one at the
>
.
😱 1
d
Yuck! There's an issue with the indentation rule too, since the opening and closing angle brackets should not be indented differently. It's no secret that I am not a fan of this annotation rule in its current state. So my advice is to disable it until it can be configured to format the code in a more readable way. You may also want to ask yourself why you are putting complicated annotations like this on generic type arguments. There is probably a better way.
m
thanks
p
Copy code
private typealias LayerSource =
    @Serializable(with = LayerSourceSerializer::class)
    SourceDto
private val styleSource: NullForUndefined<LayerSource> = NullForUndefined(null)
I had to do similar to get around this ugly mess:
Copy code
@Serializable
private data class BigDecimalWithBytes(
    val unscaledValue: @Serializable(with = LongOrBytesBigIntegerSerializer::class) BigInteger,
    val scale: Int,
)
ended up as
Copy code
@Serializable
private data class BigDecimalWithBytes(
    val unscaledValue:
    @Serializable(with = LongOrBytesBigIntegerSerializer::class)
    BigInteger,
    val scale: Int,
)
m
Interesting, thanks for the information.