-
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
Infix function confuses the indent rule #897
Comments
I'm in a similar situation, but the symptoms are a little more deterministic (so I hope the extra detail helps narrow anything down). I'm using Exposed, which likewise has an infix-heavy DSL, and sometimes needs brackets for readability. When trying a long chained expression like this: AmendmentTable
.innerJoin(PlanningSchemeAmendmentTable)
.innerJoin(PlanningSchemeTable)
.select {
(PlanningSchemeTable.code eq schemeCode) and (
(AmendmentTable.exhibitionStartDate eq null) or
(AmendmentTable.exhibitionStartDate lessEq now())
)
} the Changing it to (PlanningSchemeTable.code eq schemeCode).and( (no longer infix) removes the reported violation. Also, indenting it as advised removes the violation, unlike the above reported issue (where it alternates between errors). Your Environment
|
I do agree with both of you, that the formatting of the examples above is not what you expect. Despite that, it can not be considered as a bug in ktlint. Analog to IntelliJ IDEA, ktlint formats binary expressions between parentheses in this way. From ktlint code (IndentationRule):
If you disable the ktlint plugin in IntelliJ and reformat the code sample above, the formatted code is comparable with the result of ktlint. |
I'm not using IntelliJ for ktlint, but that's interesting. androa's original issue still sounds like a bug, because running ktlint multiple times gives inconsistent results ("0 -> 4 -> 8 -> 4 -> 8 -> 4 -> 8 and so forth"). |
Closed by #1284 |
Expected Behavior
I'm writing a DSL for expressing some rules, and use a lot of
infix
functions.If write the following:
everything works as expected. If I use the infix
then
ktlint becomes confusedObserved Behavior
ktlint can't decide on how much it wants to indent the three last lines. It just keeps sending me around fixing it back and forth from 0 -> 4 -> 8 -> 4 -> 8 -> 4 -> 8 and so forth
ktlint --verbose
says:Your Environment
The text was updated successfully, but these errors were encountered: