-
Notifications
You must be signed in to change notification settings - Fork 512
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
Formatting does not work well in classes with generics and explicit constructor #2360
Comments
I think this is related to the indentation rule. Consider the code snippets below: @file:Suppress("ktlint:standard:max-line-length")
class ClassWithGenericsAndAVeryLongName1<FirstGeneric : FirstGenericType, SecondGeneric : SecondGenericType>
internal constructor(param: SomeType)
class ClassWithGenericsAndAVeryLongName2<
FirstGeneric : FirstGenericType,
SecondGeneric : SecondGenericType,
>
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
constructor(param: SomeType)
/**
* @constructor initialize ClassWithGenericsAndAVeryLongName.
*/
class ClassWithGenericsAndAVeryLongName3<
FirstGeneric : FirstGenericType,
SecondGeneric : SecondGenericType,
>
constructor(param: SomeType) They run fine because they comply with Kotlin guidelines about class headers. Also, note that the comment location has changed. |
@jreij Tnx for the interesting examples. Can you please provide the entire Rules
But I do not think that code above is well formatted. Below would be more consistent in my opionion:
Your second example is comparable to the first. But there is a debate in #2138 how to handle this. For discourage comment locations in your third exmaple, please see faq |
@hendraanggrian @paul-dingemans thanks for the reply. Here's the full editorconfig. I'm using Android Studio with Just a few comments:
|
Indeed, something went wrong. Fixed it in the comment. |
The
But this still results in a lint violation because the KDoc should start on a newline. Although not nice, for now you can work around it as follows (assuming that you only have a few occurences of this problem):
|
Expected Behavior
I have some classes with generics for which I need to explicitly declare the
constructor
, either to document it, annotate it or add a visibility modifier to it. I expect to find a way to format these without getting ktlint errors.Observed Behavior
I am getting errors from the
type-parameter-list-spacing
anddiscouraged-comment-location
rules.Steps to Reproduce
A few code examples:
Your Environment
.editorconfig
settings:ktlint_code_style = android_studio
The text was updated successfully, but these errors were encountered: