Swiftformat: Type definitions are removed in the case of ternary operators

Created on 7 Sep 2020  路  3Comments  路  Source: nicklockwood/SwiftFormat

Since SwiftFormat version 0.46.0, type definitions have been removed from ternary operator code with the following, causing a compile error.

  • input
    ```input.swift
    let foo: Bar = Bar.hoge() ? .bar1 : .bar2

* output  
```output.swift
let foo = Bar.hoge() ? .bar1 : .bar2

The reason seems to be that the following commits don't take into ternary operators.
I tried to look for a good fix, but I couldn't think of one right away, so I'll make an Issue.

https://github.com/nicklockwood/SwiftFormat/commit/fa60eaf12aeb4981046bf48adbc03eb31271820f

bug fixed in develop

Most helpful comment

@zizi4n5 thanks for reporting, this is definitely a bug. Possible workarounds are:

1) Change the code to:

let foo = Bar.hoge() ? Bar.bar1 : .bar2

2) Add the following comment above that line:

// swiftformat:disable:next redundantType

3) Add the following to your swiftformat config

--disable redundantType

All 3 comments

@zizi4n5 thanks for reporting, this is definitely a bug. Possible workarounds are:

1) Change the code to:

let foo = Bar.hoge() ? Bar.bar1 : .bar2

2) Add the following comment above that line:

// swiftformat:disable:next redundantType

3) Add the following to your swiftformat config

--disable redundantType

@nicklockwood
Thanks for your comment.
I got around it the second way.

Add the following comment above that line:

// swiftformat:disable:next redundantType

@zizi4n5 fixed in 0.46.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cyberbeni picture Cyberbeni  路  4Comments

PompeiaPaetenari picture PompeiaPaetenari  路  4Comments

MaxDesiatov picture MaxDesiatov  路  3Comments

shripada picture shripada  路  3Comments

DavinAhn picture DavinAhn  路  4Comments