-
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
chain-method-continuation
wrapping fully qualified function/constructor calls
#2797
Comments
Please see docs for configuration of the rule. Expression will be wrapped when the configured number of operators is reached. In case you do not want that, please set it to some high number ( So there is no need for fixing this. |
I'm aware of the configuration. Those are not operators, though, it's just a fully qualified package. Not sure if my example is clear enough. |
Maybe this is some semantic interpretation that we are not aligned on. For me each |
There's a clear semantic difference between my example and the ones the rule is supposed to affect. The rule is called
is the same as
I don't see why you are referring to the full package notation as "operators", they don't do anything but qualify the class reference. If those are operators, are the dots in |
Just posting a real-world example (with some redacted words) is case that helps: // we have lots of those, and we have a rule to have one operator per line when there's more than 3 operators.
// chain-method-continuation is a perfect rule to enforce this, and we would love to adopt it
val events = eventStore
.withStreamType(CarStreamType)
.loadStream(id)
.map { it.event }
.filter { it.producer == 1L }
.sumBy { it.purchaseValue }
// This is also a very common pattern in one of my projects, we have classes with the same name
// and we need to qualify both sides in the converter code only
// This code becomes just horrible if we consider packages as "operators" as the previous messages suggest
fun protocol.client.Game1Command.toDomain(): studio.ls.game1.package1.package2.command.Game1Command = when (this) {
is protocol.client.CreateGameCommand -> studio.ls.game1.package1.package2.command.CreateGameCommand
is protocol.client.StartCommand -> studio.ls.game1.package1.package2.command.StartCommand
is protocol.client.PauseCommand -> studio.ls.game1.package1.package2.command.PauseCommand
is protocol.client.ResumeCommand -> studio.ls.game1.package1.package2.command.ResumeCommand
is protocol.client.EndGameCommand -> studio.ls.game1.package1.package2.command.EndGameCommand
} If |
It would have helped if you would have specified that you are running on an old ktlint version. In ktlint With
your code sample (plus one addition to show that it does not resolve all) is formatted by
So the constructor call is still wrapped. I will have a look to see whether I can identify chains having only one method/constructor call and no other operators like map and filter to be excluded from wrapping. |
My draft PR reproduces the issue against the master branch. I actually picked not the best block, most of the conversions are with data classes, not data objects, so they actually all wrap
Thank you. let me know if I can help. |
9a10ec0 seems to be spot-on, @paul-dingemans! |
The change is not yet ready. It has some side effects that I don't like. Once PR is raised and merged a snapshot build will be published. I do not expect to release before mid of October. |
Idea: could we check if there is an import for leaf node? Assuming this is possible as ktlint is able to figure out unused imports, we could do the following:
|
Tnx for the suggestion. I fail to understand what you mean. Can you write some unit tests that demo what you mean? |
Consider the following code:
Expected Behavior
Code should be accepted as is.
Observed Behavior
chain-method-continuation
rule fails.Steps to Reproduce
#2796
The text was updated successfully, but these errors were encountered: