Skip to content

BlueStyle chained ternary inconsistency #1094

Description

@penelopeysm

The conditional_to_if option converts ternary operators into if/else if they are over the margin:

julia> ft("a ? b : c", conditional_to_if = true)
"a ? b : c"

julia> ft("a ? b : c", conditional_to_if = true; margin=4)
"if a\n    b\nelse\n    c\nend"

BlueStyle goes one step further than that and converts chained ternaries into if/elseif/else, even if they aren't over the margin:

julia> ft("a ? b : c", BlueStyle())
"a ? b : c"

julia> ft("a ? b : c ? d : e", BlueStyle())
"if a\n    b\nelseif c\n    d\nelse\n    e\nend"

However, it's inconsistent in the way it does this, and only checks for one particular way of chaining it. For example, this doesn't get converted:

julia> ft("a ? b ? c : d : e", BlueStyle())
"a ? b ? c : d : e"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Priority 3 — see contributing docs

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions