HaxeCheckstyle / haxe-formatter

Haxe code formatter based on tokentree
https://haxecheckstyle.github.io/haxe-formatter-docs/#codesamples.CommonSamples.allman_curlies
MIT License
72 stars 16 forks source link

Long expression-if #353

Open Gama11 opened 5 years ago

Gama11 commented 5 years ago

Describe the bug
At some point it should probably switch to "regular mode" instead of trying to keep it in one line?

Input file

class Main {
    static function main() {
        var msg = if( tinf.module != inf.module ) "module "+inf.module+" should be "+tinf.module;
            else if( tinf.doc != inf.doc ) "documentation is different";
            else if( tinf.isPrivate != inf.isPrivate ) "private flag is different";
            else if( !sameType ) "type kind is different";
            else "could not merge definition";
    }
}

Broken output

class Main {
    static function main() {
        var msg = if (tinf.module != inf.module) "module " + inf.module + " should be " + tinf.module; else if (tinf.doc != inf.doc)
            "documentation is different"; else if (tinf.isPrivate != inf.isPrivate) "private flag is different"; else if (!sameType) "type kind is different"; else
            "could not merge definition";
    }
}
AlexHaxe commented 5 years ago

I plan on adding a proper wrapping option for if-else chains used in expression-ifs, so they don't run into default wrapping.