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

Refactor AnnotationRule to improve maintainability #1574

Merged

Conversation

paul-dingemans
Copy link
Collaborator

Description

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:

@Suppress("AnnotationRule") // some comment
@Bar
class Foo

Closes #1539

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.
Before format:

@Suppress("AnnotationRule")class FooBar {
    @Suppress("AnnotationRule")var foo: String
    @Suppress("AnnotationRule")fun bar() {}
}

After format:

@Suppress("AnnotationRule")
class FooBar {
    @Suppress("AnnotationRule")
    var foo: String
    @Suppress("AnnotationRule")
    fun bar() {}
}

Detect a single annotation without parameters on same line as annotated construct while the annotation is preceded by another annotation with parameters on a separate line:

class FooBar {
    @Foo("foo")
    @Bar val bar: Any
}

and format it as

class FooBar {
    @Foo("foo")
    @Bar
    val bar: Any
}

Detect lines with multiple annotations while another line also contains an annotation:

@Foo1
@Foo2 @Foo3
fun foo() {}

and format as:

@foo1
@Foo2
@foo3
fun foo() {}

Reword the violations to be more clear.

Checklist

  • PR description added
  • tests are added
  • KtLint has been applied on source code itself and violations are fixed
  • documentation is updated
  • CHANGELOG.md is updated

In case of adding a new rule:

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 paul-dingemans added this to the 0.47.0 milestone Aug 6, 2022
@paul-dingemans paul-dingemans merged commit fb7f5b4 into pinterest:master Aug 13, 2022
@paul-dingemans paul-dingemans deleted the 1539-annotation-eol-comment branch August 13, 2022 15:35
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

Successfully merging this pull request may close these issues.

AnnotationRule false positive for multiple annotations with comment
1 participant