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

Newline should be inserted before ?: in functional call chain #554

Closed
petertrr opened this issue Nov 19, 2020 · 2 comments · Fixed by #634
Closed

Newline should be inserted before ?: in functional call chain #554

petertrr opened this issue Nov 19, 2020 · 2 comments · Fixed by #634
Assignees
Labels
autofix Issues related to diktat in autofix mode bug Something isn't working

Comments

@petertrr
Copy link
Member

Describe the bug

fun foo() {
    foo.bar().baz().qux() ?: baz
}

should be fixed to

fun foo() {
    foo
        .bar()
        .baz()
        .qux()
        ?: baz
}

but ?: isn't placed on a separate line

Environment information

  • diktat version: 0.1.5
@petertrr petertrr added the bug Something isn't working label Nov 19, 2020
@petertrr petertrr self-assigned this Nov 19, 2020
@petertrr petertrr added the autofix Issues related to diktat in autofix mode label Nov 24, 2020
@orchestr7
Copy link
Member

what to do with simple expressions?
I guess for simple expressions need to have it on the same line.

a ?: b

=>

is fine in both ways:
a ?: b
and

a 
    ?: b

because in some cases linelength rule can fix it

@petertrr
Copy link
Member Author

petertrr commented Nov 27, 2020

I think rules should be the same as for usual calls chain:

  • if right-hand side of ?: is a simple expression and left-hand side too, then they can be on the same line, but also can be split if the line is too long
  • if RHS expression requires line breaks, ?: should start on a new line:
foo ?: bar.baz().qux()

should be

foo
    ?: bar
        .bar()
        .qux()
  • if LHS already has line breaks, ?: should start on a new line
foo.bar()
    .baz()
    .qux()
    ?: boo

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

Successfully merging a pull request may close this issue.

3 participants