Kotlin / Kotlin/ktfmt

Annotation location on properties

Open
#409 1 comment 5 reactions 0 assignees View on GitHub
formatting-discussions
Dominant language
Kotlin
Stars
1.3k
Forks
116
Avg merge
4d 10h
Merged PRs (30d)
15

Description

Let me start with I don't know if this is a bug or intentional behavior, but I would like to understand the reasoning behind this behavior.

Assume input:
```kotlin
@get:Rule
val benchmarkRule = BenchmarkRule()
```

this turns into when using `--kotlinlang-style`:
```kotlin
@get:Rule val benchmarkRule = BenchmarkRule()
```

What is the reasoning behind annotations being on the same line?

I see similar behavior on data classes
```
@Entity
data class EntityWithEnum(
@PrimaryKey
val id: Long,
val fruit: Fruit
)
```
becomes
```
@Entity data class EntityWithEnum(@PrimaryKey val id: Long, val fruit: Fruit)
```

and it seems that putting the annotation on the same line makes it harder to read.

Contributor guide

Open the contributing guide

Research direction

Reproduce both examples with --kotlinlang-style, then trace the formatter rules responsible for annotations on properties and data-class parameters. The issue names no source files or tests, so first locate the relevant formatting entry point and determine whether the behavior should be documented or changed. Done means the annotation-layout decision is explicit and the two examples produce the intended readable output.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.