Swiftify-Corp / Swiftify

43 stars 24 forks source link

Preserve line breaks as I wrote them #157

Open arlomedia opened 3 years ago

arlomedia commented 3 years ago

For the most part, Swiftify has been good about preserving the line breaks as I had them in my code. By comparison, this was a big problem I had with the Kotlin converter in Android Studio, which was eager to remove empty lines that I used to organize and separate blocks of code. But Swiftify has still done this in some cases:

1) If I have many elements in a conditional, it is sometimes nice to break them into separate lines for readability. For example:

if (
    (itemName == “documentButton”)
    ||
    (itemName == “recordingButton”)
    ||
    (itemName == “midiButton”)
    (etc)
) {
    [self doSomething];
}

This is changed to:

if (itemName == “documentButton”) || (itemName == “recordingButton”) || (itemName == “midiButton”) (etc) {
    doSomething()
}

Converter example: http://swiftify.me/23yd31/1

2) Conversely, I sometimes have a series of very short conditionals that I like to put on one line. For example:

if (width < min_width) { width = min_width }
if (width < max_width) { width = max_width }
if (height < min_height) { height = min_height }
if (height > max_height) { height = max_height }

(Yes, that could use max and min functions; this is just an example.) This is changed to:

if (width < min_width) {
    width = min_width
}
if (width < max_width) {
    width = max_width
}
if (height < min_height) {
    height = min_height
}
if (height > max_height) {
    height = max_height
}

Converter example: http://swiftify.me/mvecpr/2

3) Some classes have dozens of properties, and I use empty lines to group related properties. These lines were preserved for most of my project, but did a recent converter update change this? The last few files I converted had these empty lines stripped out. Hopefully this was not a side effect of issue 153. For example:

@property (nonatomic) CGSize boxSize;
@property (nonatomic) CGPoint boxPosition;
@property (nonatomic, strong) UIColor *boxColor;

@property (nonatomic) CGSize lineSize;
@property (nonatomic) CGPoint linePosition;
@property (nonatomic, strong) UIColor *lineColor;

This is changed to:

var boxSize = CGSize.zero
var boxPosition = CGPoint.zero
var boxColor: UIColor?
var lineSize = CGSize.zero
var linePosition = CGPoint.zero
var lineColor: UIColor?

Converter example: http://swiftify.me/zyu8zi

alex-swiftify commented 3 years ago

@arlomedia Thanks for the suggestions! Keeping original style is way more difficult than just reformatting the output, but we are getting there. I'll split this into a few issues, but this may take a while to be implemented.

arlomedia commented 3 years ago

Okay. I was hoping this would be a matter of not reformatting the output and just leaving the formatting as it was.