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

Incorrect "unnecessary trailing comma comma" for annotation array parameter #1379

Closed
lwasyl opened this issue Feb 22, 2022 · 2 comments · Fixed by #1382
Closed

Incorrect "unnecessary trailing comma comma" for annotation array parameter #1379

lwasyl opened this issue Feb 22, 2022 · 2 comments · Fixed by #1382

Comments

@lwasyl
Copy link

lwasyl commented Feb 22, 2022

Expected Behavior

The following file should not trigger errors:

import kotlin.reflect.KClass

@Foo(
    values = [
        Foo::class,
        Foo::class,
    ],
)
annotation class Foo(val values: Array<KClass<*>>)

Observed Behavior

Foo.kt:7:6: Lint error > [experimental:trailing-comma] Unnecessary trailing comma before ")"

When using KtLint to format the file, it removes the comma after ] producing

import kotlin.reflect.KClass

@Foo(
    values = [
        Foo::class,
        Foo::class,
    ]
)
annotation class Foo(val values: Array<KClass<*>>)

which is IMO wrong, as the trailing comma that was removed is useful + it's added by IntelliJ when formatting the file regardless

Steps to Reproduce

Your Environment

  • Version of ktlint used: 0.44.0
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): lintKotlin
  • Version of Gradle used (if applicable): 7.4
  • Operating System and version: -
  • Link to your project (if it's a public repository): -
@lwasyl lwasyl changed the title False-negative trailing comma for annotation array parameter Incorrect "unnecessary trailing comma comma" for annotation array parameter Feb 22, 2022
@paul-dingemans
Copy link
Collaborator

@lwasyl This depends on your configuration. If you are using a .editorconfig file (recommended approach) then please check whether properties below have been set:

ij_kotlin_allow_trailing_comma_on_call_site=true
ij_kotlin_allow_trailing_comma=true

@lwasyl
Copy link
Author

lwasyl commented Feb 23, 2022

I have both of those options in my .editorconfig file, and IJ seems to respect it.

[*.{kt, kts, gradle}]
indent_size = 4
insert_final_newline = true
max_line_length = 140
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants