-
Notifications
You must be signed in to change notification settings - Fork 506
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
chain-method-continuation should ignore nested classes #2455
Comments
Not everything is related to the
Usually, it is also helpful when you specify your Ktlint can not retrieve enough information from the AST / PSI to determine whether |
I'm running it in the I also added another case: fun buildBar(): Foo.Bar = Foo
.Bar
.bazFactory
.builder()
.baz()
.build()
With this we can differentiate between methods and other references. Since this rule is called In IntelliJ 'Chained function calls' with 'Chop down if too long' will wrap it as follows: // Without 'wrap first call'
fun buildBar(): Foo.Bar =
Foo.Bar.bazFactory.builder()
.baz()
.build() // With 'wrap first call'
fun buildBar(): Foo.Bar =
Foo.Bar.bazFactory
.builder()
.baz()
.build() It might make sense to add 'wrap first call' as configuration as well. |
Some examples from IntelliJ (Code Style > Kotlin > Wrapping and Braces): // Assume that the last
// allowed character is
// at the X character
// on the right X
fun buildBar(): Foo.Bar = Foo.Bar.foo().bar().baz.foo().bar().baz() // Without 'wrap first call'
fun buildBar(): Foo.Bar =
Foo.Bar.foo()
.bar().baz.foo()
.bar()
.baz() // With 'wrap first call'
fun buildBar(): Foo.Bar =
Foo.Bar.foo().bar().baz
.foo()
.bar()
.baz() and // Assume that the last
// allowed character is
// at the X character
// on the right X
fun buildBar(): Foo.Bar = Foo.Bar.baz.foo().bar().baz().foo.bar.baz.foo().bar().baz() // Without 'wrap first call'
fun buildBar(): Foo.Bar =
Foo.Bar.baz.foo()
.bar()
.baz().foo.bar.baz.foo()
.bar()
.baz() fun buildBar(): Foo.Bar =
Foo.Bar.baz
.foo()
.bar()
.baz().foo.bar.baz
.foo()
.bar()
.baz() |
Maybe it makes sense to add a separate rule Still the question about properties and classes remains. I could only think of using the first letter (if capital). Lastly if we look at the second example above, would it make sense (and be possible) to only allow class/property access to not be chopped if it's the first within a mixed chain. |
I do understand this mind jump. Do you care to explain?
Technically it is simple to check the first letter of the identifier. But, would it also apply on constants like
Mwah, not a fan of this. For all options, I have troubles to understand what the rationale would be for this change. I want to avoid to end up with tends or even hundreds of configuration possibilities as this goes against the bikeshedding principle. The current rule might seem rigid, but it as least easy to understand when and when not the chain is wrapped. |
My point is to differentiate between properties and constant access (if you would count nested class access & enums as constant). val x = Foo.BAR
.chained()
.method()
.calls() seems a lot nicer to me than val x = Foo
.BAR
.chained()
.method()
.calls()
My two main concerns are:
|
Leaving aside the 'wrap first call', I think it's probably good to have a differentiation between methods and properties. As the current rule name suggests, it's for methods. This might also be necessary for the Having two rules might make dealing with a mix of methods and properties a bit tricky though. Apart from the differentiation between methods and properties, I would also suggest again to check properties (or non-method) for first capital letter. It would be neat to not wrap static value access (including enums). |
This is indeed a valid reasoning to ignore simple reference expressions by this rule. At this moment, I think of a simple reference expression as it is preceded by another reference expression. Note that in example below the
|
Simple reference expressions like properties and enum values should be ignored by this rule as they are no method calls. Closes #2455
Simple reference expressions like properties and enum values should be ignored by this rule as they are no method calls. Closes #2455
Expected Behavior
Current Behavior
Additional information
The text was updated successfully, but these errors were encountered: