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

AnnotationOnSeparateLine should respect comments #498

Closed
arturbosch opened this issue Jun 22, 2019 · 0 comments · Fixed by #499
Closed

AnnotationOnSeparateLine should respect comments #498

arturbosch opened this issue Jun 22, 2019 · 0 comments · Fixed by #499

Comments

@arturbosch
Copy link
Contributor

arturbosch commented Jun 22, 2019

Following file has three annotations with a comment next to it:
https://github.com/arturbosch/detekt/blob/8ae133c2876a94814973ba397c6809cd4a5e514b/detekt-test/src/main/kotlin/io/gitlab/arturbosch/detekt/test/ThresholdedCodeSmellAssert.kt#L8-L9

Unfortunately KtLint does not respect this.

The first testcase in AnnotationRuleTest modified to get a violation reported:

    @Test
    fun `lint single annotation may be placed on line before annotated construct`() {
        assertThat(
            AnnotationRule().lint(
                """
                @Suppress("UnsafeCast") // False positive, see issue #1137 
                class A {
                    @JvmField
                    var x: String
                }
                """.trimIndent()
            )
        ).isEmpty()
    }

The check which fails for comments:

val annotationsWithParametersAreNotOnSeparateLines =
annotations.any { it.valueArgumentList != null } &&
!whiteSpaces.all { it.textContains('\n') }

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

Successfully merging a pull request may close this issue.

1 participant