-
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
Wrap mulitline binary expression in condition on ||
and &&
#2182
Comments
Hi @paul-dingemans why not below as the correct format
Also in your |
This rule is primarily about wrapping at the In case of the For the case of the
| Also in your if and while closing braces are not indented at the same level. Is this rule lie in ktlint_official or android? No it is not. |
No, I am talking bout |
Ok, if you mean closing parenthesis instead of braces then the answer is different. From Kotlin Coding conventions:
|
Hi, @paul-dingemans if this is available I can pick this up |
A lot of times I'll have multiline expressions where the Could an exception be made to the rule to allow this form: require(
light.isSpecified && dark.isSpecified ||
light.isUnspecified && dark.isUnspecified
) |
I do not understand this sentence. I am not a native speaker and I have the feeling that I miss some nuance here. When running the wrapping rule, the result below is less clear than the original:
Code above could be written as below, which is not ambigue and will be accepted by ktlint as long as each subexpression fits on a single line:
Above way of writing is that it makes explicit which sub-expressions are related. Also, it makes the code more refactor-proof. Suppose that
|
I am using other static checkers (e.g. detekt) which would flag this: require(
(bool1 && bool2) ||
(bool3 && bool4)
) as using unnecessary parentheses. I believe Intellij would do this as well. detekt and Intellij are correctly flagging that, since there's no need to use parentheses here; |
IntelliJ does not flag this by default. You are right about the precedence, but I think that the parentheses makes the code clearer and easier to read. You have also added a newline between the pairs of booleans for clarity. When written as single line, it just becomes harder to read when no parenthesis are used:
|
Given a multiline binary expression in an condition then wrap the right hand side of each binary expression to a new line:
should be formatted as:
This has to be done recursively per binary expression. So:
is formatted as:
The text was updated successfully, but these errors were encountered: