-
Notifications
You must be signed in to change notification settings - Fork 508
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
Multiple annotations should be allowed on the same line when construct is a constructor #673
Comments
I think in this case behaviour of
Another problem having multiple annotations for constructor on the same line - this line could more easily hit max-line limit, especially with long class name. |
I think it makes sense for the declaration examples they have there, but not constructors. Yes it increases line length, but unlike the examples they have there, new lines actually have a destructive effect on the class header declaration here. |
Came here to report the same... I think without clear examples on the Kotlin coding conventions page for constructor annotations, this isn't something that should be flagged by the rule. |
I'd like to expand the discussion to not only constructor annotations, but annotations for method parameters too. Currently (0.44.0) this is reported as an error: @Component(modules = [Foo::class, Foo::class])
interface Foo {
@Component.Factory
interface Factory {
fun create(
@BindsInstance context: Context,
@BindsInstance @Bar bar: String,
): Foo
}
}
annotation class Bar and I'm not sure what would be the suggested formatting. The following is the only variant that KtLint doesn't complain about, and I argue it's much less readable @Component(modules = [Foo::class, Foo::class])
interface Foo {
@Component.Factory
interface Factory {
fun create(
@BindsInstance context: Context,
@BindsInstance
@Bar
bar: String,
): Foo
}
}
annotation class Bar Since the annotations will most likely fit in a single line, it seems unnecessary to put them in separate lines like that |
I have same issue with - Multiple annotations should not be placed on the same line as the annotated construct (annotation) fun update(@Valid @Argument("input") input: UpdateRequest): UpdateResponse {} |
How to disable this rule? |
Please read the documentation: https://pinterest.github.io/ktlint/faq/#how-do-i-suppress-errors-for-a-lineblockfile |
another example when this rule is behaving incorrectly (validation annotation on collection type):
|
Behavior of the |
Consider the following example:
There alternative is basically this
Which I'm not sure is better. From
experimental:annotation
The text was updated successfully, but these errors were encountered: