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

AnnotationOnSeparateLine false positive #2852

Open
p-dmitriy opened this issue Oct 31, 2024 · 3 comments
Open

AnnotationOnSeparateLine false positive #2852

p-dmitriy opened this issue Oct 31, 2024 · 3 comments

Comments

@p-dmitriy
Copy link

Room has @MapColumn that can be used to specify column that should be used as map key. AnnotationOnSeparateLine triggers for such code, and in my opinion it's false positive, because there is only one annotation for the type, which is allowed by the rule description.

Steps to Reproduce

@Query("*SQL here*")
abstract fun getEntities(): Map<@MapColumn(columnName = "Id") Long, Entity>

Your Environment

  • Version of ktlint used: ktlint-ruleset-standart 0.50.0 through detekt 1.23.7
  • Android Gradle Plugin: 8.7.0
  • Room: 2.6.1
  • Version of Gradle used (if applicable): 8.10.2
  • Operating System and version: macOS 15.1
@paul-dingemans
Copy link
Collaborator

I see where you're coming from. The way how to write this construct is however a library specific preference. Ktlint can/will not make exceptions for specific library annotations.

But I can see that this is a construct that might be heavily used in certain classes, which would lead to reduced readability. Best I can do, is to consider a configuration option in which you can list the annotations that should be ignored from this rule.

Or you can just simply disable the rule entirely. See https://pinterest.github.io/ktlint/latest/faq/#how-do-i-enable-or-disable-a-rule

@p-dmitriy
Copy link
Author

As far as I see now rule doesn't follow own description. From the rule description:

Multiple annotations should be on a separate line than the annotated declaration

In my case there is single annotation (@MapColumn) for Type annotation target. @Query annotation belongs to Function target. So not first annotation nor second violates rule.
For example: if I add annotation to the function parameter this not violate the rule too. Underlying logic as I can imagine the same: different annotation targets Function and Parameter.
I'd not want to disable this rule, because it helpful, all I want is make this rule more consistent.

@paul-dingemans
Copy link
Collaborator

LOL. If you take quotes from the docs, you might better want to include the full quote:

Multiple annotations should be on a separate line than the annotated declaration; annotations with parameters should each be on separate lines; annotations should be followed by a space

@MapColumn(columnName = "Id") has a parameter columnName and therefore is forced to be written on a separate line.

Disabling the rule is how you can move forward at this moment, without being bothered by the formatting. Once the rule is made configurable, you can re-enable the rule and add this annotation to the exclude list.

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