Ballerina-lang: Anonymous functions formatted relative to the starting column of the anon function

Created on 22 Oct 2020  路  6Comments  路  Source: ballerina-platform/ballerina-lang

Refer to the following:
Peek 2020-10-22 19-57

Formatting like this leads to code aligned too much to the right

AreFormatting Point3 TeaTooling TypBug TypImprovement

All 6 comments

+1.
I think currently the table constructor behaves in the suggested way. We could try follow the same style.

Also, should the formatter be removing that new line after map(?

Its hard to determine whether to add a newline after map(, because it's yet another function argument. But if the argument exceeds the max line-length, then it should go in to the next line.

@IrushiL I think what we have done for table-constructor needs to be generalized. I mean, it should happen at the statement level, rather than the table-constructor/anon-function/etc.

A similar scenario is to when there is a function call that exeeds max-length.:

public function main() {
    var foo = bar("aaaaa", "bbbbb", "cccc", "ddddd", "eeeee","aaaaa", "bbbbb", "cccc", "ddddd", "eeeee","aaaaa", "bbbbb", "cccc", "ddddd", "eeeee","aaaaa", "bbbbb", "cccc", "ddddd", "eeeee","aaaaa", "bbbbb", "cccc", "ddddd", "eeeee");
}

Formmatered Output:

public function main() {
    var foo = bar("aaaaa", "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", 
    "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", "bbbbb", "cccc", "ddddd", 
    "eeeee");
}

Expected output:

public function main() {
    var foo = bar("aaaaa", "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", 
        "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", "bbbbb", "cccc", "ddddd", "eeeee", "aaaaa", "bbbbb", "cccc", "ddddd", 
        "eeeee");
}

Related Issue: https://github.com/ballerina-platform/ballerina-lang/issues/20534

Note: Check this behavior in query expressions.

Was this page helpful?
0 / 5 - 0 ratings