Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve line breaks as I wrote them #157

Open
arlomedia opened this issue Feb 23, 2021 · 2 comments
Open

Preserve line breaks as I wrote them #157

arlomedia opened this issue Feb 23, 2021 · 2 comments

Comments

@arlomedia
Copy link

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

  1. 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

  1. 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
Copy link
Member

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants