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

Invalid annotation failure for @receiver target annotation with parameter #885

Closed
adamsp opened this issue Sep 2, 2020 · 2 comments · Fixed by #913
Closed

Invalid annotation failure for @receiver target annotation with parameter #885

adamsp opened this issue Sep 2, 2020 · 2 comments · Fixed by #913
Labels
Milestone

Comments

@adamsp
Copy link

adamsp commented Sep 2, 2020

Expected Behavior

@receiver annotations with parameters should not be required to be on a different line.

Observed Behavior

When annotating with @receiver:SomeAnnotation(SomeParameter), the AnnotationRule fails with the following:

Annotations with parameters should all be placed on separate lines prior to the annotated construct

Steps to Reproduce

Drop this in a Kotlin file and run ktlint on it:

interface AnnotationExample {
  fun @receiver:ExampleAnnotation("Breaks Ktlint") ExampleClass.provideExample(): ExampleInterface
}

interface ExampleInterface
class ExampleClass : ExampleInterface

annotation class ExampleAnnotation(val arg: String)

You can successfully meet the criteria with the following:

  fun @receiver:ExampleAnnotation("Breaks Ktlint")
  ExampleClass.provideExample(): ExampleInterface

However this is quite unexpected as a reader, and feels inconsistent when parameter-free annotations work just fine:

fun @receiver:ExampleAnnotation ExampleClass.provideExample(): ExampleInterface

Your Environment

./gradlew ktlint --version

------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------

Build time:   2020-08-25 16:29:12 UTC
Revision:     f2d1fb54a951d8b11d25748e4711bec8d128d7e3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          1.8.0_242-release (JetBrains s.r.o 25.242-b3-6222593)
OS:           Mac OS X 10.15.6 x86_64
@romtsn romtsn added the bug label Sep 2, 2020
@romtsn
Copy link
Collaborator

romtsn commented Sep 2, 2020

Thanks for reporting! We'll take a look. And the version of ktlint is 0.37.2 I assume (it seems you've missed to add it to the report)?

@ZacSweers
Copy link

We're on 0.38.1

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