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

AnnotationRule false positive for multiple annotations with comment #1539

Closed
kvn-stgl opened this issue Jul 8, 2022 · 0 comments · Fixed by #1574
Closed

AnnotationRule false positive for multiple annotations with comment #1539

kvn-stgl opened this issue Jul 8, 2022 · 0 comments · Fixed by #1574

Comments

@kvn-stgl
Copy link

kvn-stgl commented Jul 8, 2022

Expected Behavior

We should be allowed to write multiple annotations on separate lines which are followed by comments. As example:

@Suppress("AnnotationRule") // some comment
@Suppress("AnnotationRule")
@Suppress("AnnotationRule")
class FooBar1 

Or for kotlin script:

@file:Suppress("AnnotationRule") // some comment
@file:DependsOn("ktlint")
@file:DependsOn("ktlint")

Observed Behavior

The AnnotationRule is showing the following error: Annotations with parameters should all be placed on separate lines prior to the annotated construct

Steps to Reproduce

The following test should show the problem:

    @Test
    fun `Given multiple annotations with a parameter followed by a EOL comment`() {
        val code =
            """
            @Suppress("AnnotationRule") // some comment
            @Suppress("AnnotationRule")
            @Suppress("AnnotationRule")
            class FooBar1
            """.trimIndent()

        annotationRuleAssertThat(code).hasNoLintViolations()
    }

Your Environment

  • Version of ktlint used: 0.46.1
@paul-dingemans paul-dingemans added this to the 0.47.0 milestone Jul 9, 2022
paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Aug 6, 2022
Replace (biggest part of) processing of MODIFIER_LIST and FILE_ANNOTATION_LIST with processing of
individual ANNOTATION_ENTRY. This allows ANNOTATION_ENTRY to be followed by EOL_COMMENT plus
another ANNOTATION_ENTRY.

Reword the violations to be more clear.

Annotation with parameter(s) on same line as annotated construct is rewritten to
annotation on a separate line directly as otherwise a lint violation would remain
after the first format.

Closes pinterest#1539
paul-dingemans added a commit that referenced this issue Aug 13, 2022
* Refactor AnnotationRule to improve maintainability

Replace (biggest part of) processing of MODIFIER_LIST and FILE_ANNOTATION_LIST with processing of
individual ANNOTATION_ENTRY. This allows ANNOTATION_ENTRY to be followed by EOL_COMMENT plus
another ANNOTATION_ENTRY.

Reword the violations to be more clear.

Annotation with parameter(s) on same line as annotated construct is rewritten to
annotation on a separate line directly as otherwise a lint violation would remain
after the first format.

Closes #1539
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