Skip to content
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

WRONG_INDENTATION: aligned chained method calls reported as false positives #1336

Closed
0x6675636b796f75676974687562 opened this issue May 31, 2022 · 1 comment · Fixed by #1442
Assignees
Labels
bug Something isn't working
Milestone

Comments

@0x6675636b796f75676974687562
Copy link
Member

0x6675636b796f75676974687562 commented May 31, 2022

Consider this code example:

fun LocalDateTime.updateTime(
    hour: Int? = null,
    minute: Int? = null,
    second: Int? = null,
): LocalDateTime = withHour(hour ?: getHour())
    .withMinute(minute ?: getMinute())
    .withSecond(second ?: getSecond())

1336

Chained method calls in lines 6-7 are normally aligned (e. g.: IDEA does so). Yet, DiKTat reports this as an error, suggesting the following formatting. extendedIndentBeforeDot on (the default):

fun LocalDateTime.updateTime(
    hour: Int? = null,
    minute: Int? = null,
    second: Int? = null,
): LocalDateTime = withHour(hour ?: getHour())
        .withMinute(minute ?: getMinute())
                .withSecond(second ?: getSecond())

— and extendedIndentBeforeDot off:

fun LocalDateTime.updateTime(
    hour: Int? = null,
    minute: Int? = null,
    second: Int? = null,
): LocalDateTime = withHour(hour ?: getHour())
    .withMinute(minute ?: getMinute())
        .withSecond(second ?: getSecond())

The corresponding IDEA code style flag is CONTINUATION_INDENT_FOR_CHAINED_CALLS, on by default.

@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added the bug Something isn't working label May 31, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added this to the 1.1.1 milestone May 31, 2022
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 changed the title WRONG_INDENTATION: aligned chained method calls reported as false positives by the linter WRONG_INDENTATION: aligned chained method calls reported as false positives Jun 1, 2022
@0x6675636b796f75676974687562
Copy link
Member Author

0x6675636b796f75676974687562 commented Jun 1, 2022

A prerequisite for this is an expression-body function, i. e. none of the below will trigger the issue:

val a = expression

val b =
        expression

val c
    get() =
            expression

fun d() {
    expression
}

while this may:

fun e() =
        expression

Minimal repro (assuming extendedIndentBeforeDot is on):

fun f() = first()
        .second()
        .third() // <- here, DiKTat suggest a double continuation indent (16) instead of a single continuation indent.

At the same time, this fragment produces no warnings (which is correct):

fun f() =
        first() // Continuation indent
                .second() // Double continuation indent
                .third() // Double continuation indent aligned

Another minimal repro:

fun f() = g(first()
        .second() // DiKTat suggest an indentation of 12
        .third() // DiKTat suggest an indentation of 20
        .fourth()) // DiKTat suggest an indentation of 28

Similarly, this fragment produces no warnings (which is correct, too):

fun f() = g(
        first()
                .second()
                .third()
                .fourth())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant