Skip to content
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

[1.3.0] Data class comments break indentation formatting #2689

Closed
Bencodes opened this issue Jun 5, 2024 · 3 comments · Fixed by #2716
Closed

[1.3.0] Data class comments break indentation formatting #2689

Bencodes opened this issue Jun 5, 2024 · 3 comments · Fixed by #2716
Milestone

Comments

@Bencodes
Copy link

Bencodes commented Jun 5, 2024

Expected Behavior

Formatting data classes with // comments should produce valid Kotlin code.

Observed Behavior

Auto fixing produces invalid Kotlin code that does not compile.

Steps to Reproduce

Run ktlint -f against the following Kotlin data class:

data class Foo(
    // Foo
    val foo: String,
    val bar: String,
)

Results in:

data class Foo(
    // Fooval foo: String, val bar: String,)

KtLint does not fail if you replace the // Foo comment with /* Foo */.

Your Environment

  • Version of ktlint used: 1.3.0
  • Relevant parts of the .editorconfig settings: An empty configuration reproduces this error.
@paul-dingemans
Copy link
Collaborator

Tnx for reporting. Next time please enclose your .editorconfig settings as well. It turns out that this problem only occurs with non-default code style android_studio.

@paul-dingemans
Copy link
Collaborator

  • Relevant parts of the .editorconfig settings: An empty configuration reproduces this error.

This is not correct. With an empty .editorconfig you're using ktlint_official code style which does not reproduces this problem. The .editorconfig below does reproduce the problem:

root = true

[*.{kt,kts}]
ktlint_code_style = android_studio

@paul-dingemans
Copy link
Collaborator

The problem could also reproduced with the other code styles given that additional .editorconfig properties are set. The fix is to explicitly check that the primary constructory does not contain any EOL-comment in the parameter list.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
2 participants