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

False positive 'Unnecessary semicolon' and 'Missing trailing comma before ";"' for enums with companion object #1743

Closed
oleksandr-bezushko-axon opened this issue Dec 23, 2022 · 1 comment

Comments

@oleksandr-bezushko-axon
package some.package

enum class TestEnum(val someField: String) {
    A("a"),
    B("b"),
    C("c");

    companion object {
        fun findBySomeField(field: String): TestEnum? = values().find { it.someField == field }
    }
}

If run this snipped of code with ktlint v0.48.0, you'll get the following output:

/path/to/TestEnum.kt:6:11: Unnecessary semicolon (no-semi)
/path/to/TestEnum.kt:6:11: Missing trailing comma before ";" (trailing-comma-on-declaration-site)

Summary error count (descending) by rule:
  no-semi: 1
  trailing-comma-on-declaration-site: 1

Telling ktlint to resolve the issues by running ktlint -F /path/to/TestEnum.kt produces the following code:

package some.package

enum class TestEnum(val someField: String) {
    A("a"),
    B("b"),
    C("c")

    companion object {
        fun findBySomeField(field: String): TestEnum? = values().find { it.someField == field }
    },
}

which is an invalid code:

image

image

Your Environment

  • Version of ktlint used: 0.48.0
  • Relevant parts of the .editorconfig settings: not used
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): ktlint CLI v0.48.0
  • Version of Gradle used (if applicable): not applicable
  • Operating System and version: archlinux
@paul-dingemans
Copy link
Collaborator

Duplicate of #1733

@paul-dingemans paul-dingemans marked this as a duplicate of #1733 Dec 23, 2022
@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants