-
Notifications
You must be signed in to change notification settings - Fork 503
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
Unnecessary newline before "(" for nullable lambda definitions. #1255
Comments
I am not able to reproduce the problem with the given example. Also the output Please put your sample code in a new file and run ktlint again on that file with options "--verbose --debug". |
This is a minimal file where I see this issue:
TestFormatting.kt:6:8 Unnecessary newline before "(" I don't see anything unusual in the output
For the reference pasting my .editorconfig:
|
Thanks. I can now reproduce the problem. The In order to resolve this, it should be ensured that rules only have one task and that no two rules exist that are doing the same task. In my opinion the wrapping functionality should be extracted from the |
In this case the parameter-list-wrapping rule is a bit too aggressive. Because the max-line-length is exceeded, this rule decides to move each parameter to a separate line but this should not have been applied to the parameters of the lambda as well. So the code should have been wrapped as follows:
This formatting is also accepted by the default IntelliJ IDEA formatting. It becomes more interestingly when the lambda parameter would still exceed the max-line-lenght. In that case, I suggest to not wrap the rule (this strategy is used in other rules as well). Reason for this is that the default IntelliJ IDEA formatting is not able, to format this properly. For example:
will be changed to code below by default IntelliJ IDEA:
|
Expected Behavior
No error reported
Observed Behavior
ktlint is formatting following line
var changesListener: ((width: Double?, depth: Double?, length: Double?, area: Double?) -> Unit)? = null
like this
but at the same time it reports an issue:
xxx.kt:21:9: Unnecessary newline before "("
Your Environment
org.jlleitschuh.gradle:ktlint-gradle:10.2.0
The text was updated successfully, but these errors were encountered: