Skip to content

6.3.0: Non-idempotent output with long lines and ternary operator #1248

Description

@jrose-signal

The following input (reduced from generated code, don't blame me)

struct Outer {
    func test() {
        let ffiStructKeepAlive: (FixedByteArrayConverter<FixedByteArrayHelper15>.KeepAlive?, IdentityConverter<Int32>.KeepAlive?, )? = (media_id_keepalive != nil || cdn_keepalive != nil || false) ? (media_id_keepalive, cdn_keepalive,) : nil
    }
}

formats to

struct Outer {
    func test() {
        let ffiStructKeepAlive:
            (FixedByteArrayConverter<FixedByteArrayHelper15>.KeepAlive?, IdentityConverter<Int32>.KeepAlive?, )? =
                (media_id_keepalive != nil || cdn_keepalive != nil || false) ? (media_id_keepalive, cdn_keepalive,)
                : nil
    }
}

but if you run it through the formatter again you get

struct Outer {
    func test() {
        let ffiStructKeepAlive:
            (FixedByteArrayConverter<FixedByteArrayHelper15>.KeepAlive?, IdentityConverter<Int32>.KeepAlive?, )? =
                (media_id_keepalive != nil || cdn_keepalive != nil || false)
                ? (media_id_keepalive, cdn_keepalive,)
                : nil
    }
}

Our .swift-format:

{
    "version": 1,
    "lineLength": 120,
    "indentation": { "spaces": 4 },
    "indentConditionalCompilationBlocks": false,
    "lineBreakBeforeEachArgument": true,
    "lineBreakBetweenDeclarationAttributes": true,
    "prioritizeKeepingFunctionOutputTogether": true
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions